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
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.

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.

get_content_template_display(*, field=<django.db.models.fields.CharField: content_template>)
get_detail_template_display(*, field=<django.db.models.fields.CharField: detail_template>)
get_next_by_creation_date(*, field=<django.db.models.fields.DateTimeField: creation_date>, is_next=True, **kwargs)
get_next_by_last_update(*, field=<django.db.models.fields.DateTimeField: last_update>, is_next=True, **kwargs)
get_next_by_publication_date(*, field=<django.db.models.fields.DateTimeField: publication_date>, is_next=True, **kwargs)
get_previous_by_creation_date(*, field=<django.db.models.fields.DateTimeField: creation_date>, is_next=False, **kwargs)
get_previous_by_last_update(*, field=<django.db.models.fields.DateTimeField: last_update>, is_next=False, **kwargs)
get_previous_by_publication_date(*, field=<django.db.models.fields.DateTimeField: publication_date>, is_next=False, **kwargs)
get_status_display(*, field=<django.db.models.fields.IntegerField: status>)
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.

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

Bases: object

abstract = False
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

Bases: object

abstract = False
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

Bases: object

abstract = False
content

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

html_content

Returns the “content” field formatted in HTML.

html_preview

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

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

Bases: object

abstract = False
content_template

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

get_content_template_display(*, field=<django.db.models.fields.CharField: content_template>)
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

Bases: object

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 = 'entry'
verbose_name_plural = 'entries'
STATUS_CHOICES = ((0, 'draft'), (1, 'hidden'), (2, 'published'))
creation_date

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

end_publication

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

get_absolute_url()

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

get_next_by_creation_date(*, field=<django.db.models.fields.DateTimeField: creation_date>, is_next=True, **kwargs)
get_next_by_last_update(*, field=<django.db.models.fields.DateTimeField: last_update>, is_next=True, **kwargs)
get_next_by_publication_date(*, field=<django.db.models.fields.DateTimeField: publication_date>, is_next=True, **kwargs)
get_previous_by_creation_date(*, field=<django.db.models.fields.DateTimeField: creation_date>, is_next=False, **kwargs)
get_previous_by_last_update(*, field=<django.db.models.fields.DateTimeField: last_update>, is_next=False, **kwargs)
get_previous_by_publication_date(*, field=<django.db.models.fields.DateTimeField: publication_date>, is_next=False, **kwargs)
get_status_display(*, field=<django.db.models.fields.IntegerField: status>)
is_actual

Checks if an entry is within his publication period.

is_visible

Checks if an entry is visible and published.

last_update

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

next_entry

Returns the next published entry if exists.

objects
previous_entry

Returns the previous published entry if exists.

previous_next_entries

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

publication_date

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

published
save(*args, **kwargs)

Overrides the save method to update the the last_update field.

short_url

Returns the entry’s short url.

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.

slug

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

start_publication

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

status

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

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

Bases: object

abstract = False
detail_template

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

get_detail_template_display(*, field=<django.db.models.fields.CharField: detail_template>)
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

Bases: object

abstract = False
comment_count

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

comment_enabled

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

comments

Returns a queryset of the published comments.

comments_are_open

Checks if the comments are open with the AUTO_CLOSE_COMMENTS_AFTER setting.

discussion_is_still_open(discussion_type, auto_close_after)

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

discussions

Returns a queryset of the published discussions.

pingback_count

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

pingback_enabled

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

pingbacks

Returns a queryset of the published pingbacks.

pingbacks_are_open

Checks if the pingbacks are open with the AUTO_CLOSE_PINGBACKS_AFTER setting.

trackback_count

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

trackback_enabled

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

trackbacks

Return a queryset of the published trackbacks.

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

Bases: object

abstract = False
excerpt

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

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

Bases: object

abstract = False
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

Bases: object

abstract = False
image_caption

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

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

Bases: object

abstract = False
html_lead

Returns the “lead” field formatted in HTML.

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

Bases: object

abstract = False
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

Bases: object

abstract = False
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

Bases: object

abstract = False
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.

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

Bases: object

abstract = False
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.