models_bases Package

models_bases Package

Base models for Zinnia

zinnia.models_bases.load_model_class(model_path)

Load by import a class by a string path like: ‘module.models.MyModel’. This mechanism allows extension and customization of the Entry model class.

entry Module

Base entry models for Zinnia

class zinnia.models_bases.entry.AbstractEntry(*args, **kwargs)

Bases: zinnia.models_bases.entry.CoreEntry, zinnia.models_bases.entry.ContentEntry, zinnia.models_bases.entry.DiscussionsEntry, zinnia.models_bases.entry.RelatedEntry, zinnia.models_bases.entry.LeadEntry, zinnia.models_bases.entry.ExcerptEntry, zinnia.models_bases.entry.ImageEntry, zinnia.models_bases.entry.FeaturedEntry, zinnia.models_bases.entry.AuthorsEntry, zinnia.models_bases.entry.CategoriesEntry, zinnia.models_bases.entry.TagsEntry, zinnia.models_bases.entry.LoginRequiredEntry, zinnia.models_bases.entry.PasswordRequiredEntry, zinnia.models_bases.entry.ContentTemplateEntry, zinnia.models_bases.entry.DetailTemplateEntry

Final abstract entry model class assembling all the abstract entry model classes into a single one.

In this manner we can override some fields without reimplemting all the AbstractEntry.

Parameters:
  • title (CharField) – Title
  • slug (SlugField) – Used to build the entry’s URL.
  • status (IntegerField) – Status
  • publication_date (DateTimeField) – Used to build the entry’s URL.
  • start_publication (DateTimeField) – Start date of publication.
  • end_publication (DateTimeField) – End date of publication.
  • creation_date (DateTimeField) – Creation date
  • last_update (DateTimeField) – Last update
  • content (TextField) – Content
  • comment_enabled (BooleanField) – Allows comments if checked.
  • pingback_enabled (BooleanField) – Allows pingbacks if checked.
  • trackback_enabled (BooleanField) – Allows trackbacks if checked.
  • comment_count (IntegerField) – Comment count
  • pingback_count (IntegerField) – Pingback count
  • trackback_count (IntegerField) – Trackback count
  • lead (TextField) – Lead paragraph
  • excerpt (TextField) – Used for SEO purposes.
  • image (ImageField) – Used for illustration.
  • image_caption (TextField) – Image’s caption.
  • featured (BooleanField) – Featured
  • tags (TagField) – Tags
  • login_required (BooleanField) – Only authenticated users can view the entry.
  • password (CharField) – Protects the entry with a password.
  • content_template (CharField) – Template used to display the entry’s content.
  • detail_template (CharField) – Template used to display the entry’s detail page.
class Meta

Bases: zinnia.models_bases.entry.Meta

abstract = False
AbstractEntry.authors

Accessor to the related objects manager on the forward and reverse sides of a many-to-many relation.

In the example:

class Pizza(Model):
    toppings = ManyToManyField(Topping, related_name='pizzas')

pizza.toppings and topping.pizzas are ManyToManyDescriptor instances.

Most of the implementation is delegated to a dynamically defined manager class built by create_forward_many_to_many_manager() defined below.

AbstractEntry.categories

Accessor to the related objects manager on the forward and reverse sides of a many-to-many relation.

In the example:

class Pizza(Model):
    toppings = ManyToManyField(Topping, related_name='pizzas')

pizza.toppings and topping.pizzas are ManyToManyDescriptor instances.

Most of the implementation is delegated to a dynamically defined manager class built by create_forward_many_to_many_manager() defined below.

AbstractEntry.get_content_template_display(*moreargs, **morekwargs)
AbstractEntry.get_detail_template_display(*moreargs, **morekwargs)
AbstractEntry.get_next_by_creation_date(*moreargs, **morekwargs)
AbstractEntry.get_next_by_last_update(*moreargs, **morekwargs)
AbstractEntry.get_next_by_publication_date(*moreargs, **morekwargs)
AbstractEntry.get_previous_by_creation_date(*moreargs, **morekwargs)
AbstractEntry.get_previous_by_last_update(*moreargs, **morekwargs)
AbstractEntry.get_previous_by_publication_date(*moreargs, **morekwargs)
AbstractEntry.get_status_display(*moreargs, **morekwargs)
AbstractEntry.related

Accessor to the related objects manager on the forward and reverse sides of a many-to-many relation.

In the example:

class Pizza(Model):
    toppings = ManyToManyField(Topping, related_name='pizzas')

pizza.toppings and topping.pizzas are ManyToManyDescriptor instances.

Most of the implementation is delegated to a dynamically defined manager class built by create_forward_many_to_many_manager() defined below.

AbstractEntry.sites

Accessor to the related objects manager on the forward and reverse sides of a many-to-many relation.

In the example:

class Pizza(Model):
    toppings = ManyToManyField(Topping, related_name='pizzas')

pizza.toppings and topping.pizzas are ManyToManyDescriptor instances.

Most of the implementation is delegated to a dynamically defined manager class built by create_forward_many_to_many_manager() defined below.

class zinnia.models_bases.entry.AuthorsEntry(*args, **kwargs)

Bases: django.db.models.base.Model

Abstract model class to add relationship between the entries and their authors.

class Meta
abstract = False
AuthorsEntry.authors

Accessor to the related objects manager on the forward and reverse sides of a many-to-many relation.

In the example:

class Pizza(Model):
    toppings = ManyToManyField(Topping, related_name='pizzas')

pizza.toppings and topping.pizzas are ManyToManyDescriptor instances.

Most of the implementation is delegated to a dynamically defined manager class built by create_forward_many_to_many_manager() defined below.

class zinnia.models_bases.entry.CategoriesEntry(*args, **kwargs)

Bases: django.db.models.base.Model

Abstract model class to categorize the entries.

class Meta
abstract = False
CategoriesEntry.categories

Accessor to the related objects manager on the forward and reverse sides of a many-to-many relation.

In the example:

class Pizza(Model):
    toppings = ManyToManyField(Topping, related_name='pizzas')

pizza.toppings and topping.pizzas are ManyToManyDescriptor instances.

Most of the implementation is delegated to a dynamically defined manager class built by create_forward_many_to_many_manager() defined below.

class zinnia.models_bases.entry.ContentEntry(*args, **kwargs)

Bases: django.db.models.base.Model

Abstract content model class providing field and methods to write content inside an entry.

Parameters:content (TextField) – Content
class Meta
abstract = False
ContentEntry.content

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

ContentEntry.html_content

Returns the “content” field formatted in HTML.

ContentEntry.html_preview

Returns a preview of the “content” field or the “lead” field if defined, formatted in HTML.

ContentEntry.word_count

Counts the number of words used in the content.

class zinnia.models_bases.entry.ContentTemplateEntry(*args, **kwargs)

Bases: django.db.models.base.Model

Abstract model class to display entry’s content with a custom template.

Parameters:content_template (CharField) – Template used to display the entry’s content.
class Meta
abstract = False
ContentTemplateEntry.content_template

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

ContentTemplateEntry.get_content_template_display(*moreargs, **morekwargs)
class zinnia.models_bases.entry.CoreEntry(*args, **kwargs)

Bases: django.db.models.base.Model

Abstract core entry model class providing the fields and methods required for publishing content over time.

Parameters:
  • title (CharField) – Title
  • slug (SlugField) – Used to build the entry’s URL.
  • status (IntegerField) – Status
  • publication_date (DateTimeField) – Used to build the entry’s URL.
  • start_publication (DateTimeField) – Start date of publication.
  • end_publication (DateTimeField) – End date of publication.
  • creation_date (DateTimeField) – Creation date
  • last_update (DateTimeField) – Last update
class Meta

CoreEntry’s meta informations.

abstract = False
get_latest_by = 'publication_date'
index_together = [['slug', 'publication_date'], ['status', 'publication_date', 'start_publication', 'end_publication']]
ordering = ['-publication_date']
permissions = (('can_view_all', 'Can view all entries'), ('can_change_status', 'Can change status'), ('can_change_author', 'Can change author(s)'))
verbose_name = <django.utils.functional.__proxy__ object>
verbose_name_plural = <django.utils.functional.__proxy__ object>
CoreEntry.STATUS_CHOICES = ((0, <django.utils.functional.__proxy__ object>), (1, <django.utils.functional.__proxy__ object>), (2, <django.utils.functional.__proxy__ object>))
CoreEntry.creation_date

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

CoreEntry.end_publication

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

CoreEntry.get_absolute_url(*args, **kwargs)

Builds and returns the entry’s URL based on the slug and the creation date.

CoreEntry.get_next_by_creation_date(*moreargs, **morekwargs)
CoreEntry.get_next_by_last_update(*moreargs, **morekwargs)
CoreEntry.get_next_by_publication_date(*moreargs, **morekwargs)
CoreEntry.get_previous_by_creation_date(*moreargs, **morekwargs)
CoreEntry.get_previous_by_last_update(*moreargs, **morekwargs)
CoreEntry.get_previous_by_publication_date(*moreargs, **morekwargs)
CoreEntry.get_status_display(*moreargs, **morekwargs)
CoreEntry.is_actual

Checks if an entry is within his publication period.

CoreEntry.is_visible

Checks if an entry is visible and published.

CoreEntry.last_update

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

CoreEntry.next_entry

Returns the next published entry if exists.

CoreEntry.objects
CoreEntry.previous_entry

Returns the previous published entry if exists.

CoreEntry.previous_next_entries

Returns and caches a tuple containing the next and previous published entries. Only available if the entry instance is published.

CoreEntry.publication_date

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

CoreEntry.published
CoreEntry.save(*args, **kwargs)

Overrides the save method to update the the last_update field.

CoreEntry.short_url

Returns the entry’s short url.

CoreEntry.sites

Accessor to the related objects manager on the forward and reverse sides of a many-to-many relation.

In the example:

class Pizza(Model):
    toppings = ManyToManyField(Topping, related_name='pizzas')

pizza.toppings and topping.pizzas are ManyToManyDescriptor instances.

Most of the implementation is delegated to a dynamically defined manager class built by create_forward_many_to_many_manager() defined below.

CoreEntry.slug

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

CoreEntry.start_publication

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

CoreEntry.status

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

CoreEntry.title

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

class zinnia.models_bases.entry.DetailTemplateEntry(*args, **kwargs)

Bases: django.db.models.base.Model

Abstract model class to display entries with a custom template if needed on the detail page.

Parameters:detail_template (CharField) – Template used to display the entry’s detail page.
class Meta
abstract = False
DetailTemplateEntry.detail_template

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

DetailTemplateEntry.get_detail_template_display(*moreargs, **morekwargs)
class zinnia.models_bases.entry.DiscussionsEntry(*args, **kwargs)

Bases: django.db.models.base.Model

Abstract discussion model class providing the fields and methods to manage the discussions (comments, pingbacks, trackbacks).

Parameters:
  • comment_enabled (BooleanField) – Allows comments if checked.
  • pingback_enabled (BooleanField) – Allows pingbacks if checked.
  • trackback_enabled (BooleanField) – Allows trackbacks if checked.
  • comment_count (IntegerField) – Comment count
  • pingback_count (IntegerField) – Pingback count
  • trackback_count (IntegerField) – Trackback count
class Meta
abstract = False
DiscussionsEntry.comment_count

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

DiscussionsEntry.comment_enabled

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

DiscussionsEntry.comments

Returns a queryset of the published comments.

DiscussionsEntry.comments_are_open

Checks if the comments are open with the AUTO_CLOSE_COMMENTS_AFTER setting.

DiscussionsEntry.discussion_is_still_open(discussion_type, auto_close_after)

Checks if a type of discussion is still open are a certain number of days.

DiscussionsEntry.discussions

Returns a queryset of the published discussions.

DiscussionsEntry.pingback_count

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

DiscussionsEntry.pingback_enabled

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

DiscussionsEntry.pingbacks

Returns a queryset of the published pingbacks.

DiscussionsEntry.pingbacks_are_open

Checks if the pingbacks are open with the AUTO_CLOSE_PINGBACKS_AFTER setting.

DiscussionsEntry.trackback_count

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

DiscussionsEntry.trackback_enabled

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

DiscussionsEntry.trackbacks

Return a queryset of the published trackbacks.

DiscussionsEntry.trackbacks_are_open

Checks if the trackbacks are open with the AUTO_CLOSE_TRACKBACKS_AFTER setting.

class zinnia.models_bases.entry.ExcerptEntry(*args, **kwargs)

Bases: django.db.models.base.Model

Abstract model class to add an excerpt to the entries.

Parameters:excerpt (TextField) – Used for SEO purposes.
class Meta
abstract = False
ExcerptEntry.excerpt

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

ExcerptEntry.save(*args, **kwargs)

Overrides the save method to create an excerpt from the content field if void.

class zinnia.models_bases.entry.FeaturedEntry(*args, **kwargs)

Bases: django.db.models.base.Model

Abstract model class to mark entries as featured.

Parameters:featured (BooleanField) – Featured
class Meta
abstract = False
FeaturedEntry.featured

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

class zinnia.models_bases.entry.ImageEntry(*args, **kwargs)

Bases: django.db.models.base.Model

Abstract model class to add an image for illustrating the entries.

Parameters:
  • image (ImageField) – Used for illustration.
  • image_caption (TextField) – Image’s caption.
class Meta
abstract = False
ImageEntry.image_caption

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

ImageEntry.image_upload_to(filename)

Compute the upload path for the image field.

class zinnia.models_bases.entry.LeadEntry(*args, **kwargs)

Bases: django.db.models.base.Model

Abstract model class providing a lead content to the entries.

Parameters:lead (TextField) – Lead paragraph
class Meta
abstract = False
LeadEntry.html_lead

Returns the “lead” field formatted in HTML.

LeadEntry.lead

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

class zinnia.models_bases.entry.LoginRequiredEntry(*args, **kwargs)

Bases: django.db.models.base.Model

Abstract model class to restrcit the display of the entry on authenticated users.

Parameters:login_required (BooleanField) – Only authenticated users can view the entry.
class Meta
abstract = False
LoginRequiredEntry.login_required

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

class zinnia.models_bases.entry.PasswordRequiredEntry(*args, **kwargs)

Bases: django.db.models.base.Model

Abstract model class to restrict the display of the entry to users knowing the password.

Parameters:password (CharField) – Protects the entry with a password.
class Meta
abstract = False
PasswordRequiredEntry.password

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

class zinnia.models_bases.entry.RelatedEntry(*args, **kwargs)

Bases: django.db.models.base.Model

Abstract model class for making manual relations between the differents entries.

class Meta
abstract = False
RelatedEntry.related

Accessor to the related objects manager on the forward and reverse sides of a many-to-many relation.

In the example:

class Pizza(Model):
    toppings = ManyToManyField(Topping, related_name='pizzas')

pizza.toppings and topping.pizzas are ManyToManyDescriptor instances.

Most of the implementation is delegated to a dynamically defined manager class built by create_forward_many_to_many_manager() defined below.

RelatedEntry.related_published

Returns only related entries published.

class zinnia.models_bases.entry.TagsEntry(*args, **kwargs)

Bases: django.db.models.base.Model

Abstract model class to add tags to the entries.

Parameters:tags (TagField) – Tags
class Meta
abstract = False
TagsEntry.tags_list

Return iterable list of tags.

zinnia.models_bases.entry.image_upload_to_dispatcher(entry, filename)

Dispatch function to allow overriding of image_upload_to method.

Outside the model for fixing an issue with Django’s migrations on Python 2.