Mixin models

class helpfulfields.models.ChangeTracking(*args, **kwargs)[source]

Abstract model for extending custom models with an audit of when things were changed. By extension, allows us to use get_latest_by and get_next_by_FOO() if we want to.

Note

It transpires that this is basically an accidental rewrite of django-model-utils TimeStampedModel, though it provides a few extra bits.

created = None

a datetime representing the original date this object was saved. Represented as a DateTimeField.

created_recently(**kwargs)[source]

Was this object created recently? Accepts a list of kwargs which are passed directly to timedelta; in the absence of any kwargs the timedelta is told 30 minutes is recent.

Returns:whether or not this object was recently created
Return type:boolean
modified = None

a datetime representing the last time this object was changed. Represented as a DateTimeField.

modified_recently(**kwargs)[source]

Was this object changed recently? Accepts a list of kwargs which are passed directly to timedelta; in the absence of any kwargs the timedelta is told 30 minutes is recent.

Returns:whether or not this object was recently changed.
Return type:boolean
class helpfulfields.models.DatePublishing(*args, **kwargs)[source]

A perennial favourite, publish start and end dates, as an abstract model.

Has the same is_published attribute that Publishing has.

For querying, this should be combined with DatePublishingQuerySet.

is_published[source]

For API compatibility with the alternate publishing model Publishing which uses a boolean property, this method is accessed the same way, and is decorated with property() for this reason.

Returns:Whether or not this object is currently visible
Return type:boolean
publish_on = None

Defaults to datetime.datetime.now() - the date on which this should be available on the site. Represented as a DateTimeField.

unpublish_on = None

the datetime on which this should expire from the site. Represented as a DateTimeField.

class helpfulfields.models.Generic(*args, **kwargs)[source]

For handling generic relations in a uniform way (assuming that only 1 is required on the subclassing model).

content_id = None

Uses a CharField, so that apps may have non-integer primary keys (eg: uuid4())

content_object

A virtual field which allows us to get the actual object, as and when we need it. Calling this will almost always result in a query.

content_type

The foreign key to Django‘s internal ContentType for a specific model. Doesn’t provide a related_name from ContentType back to the subclass implementing this model.

class helpfulfields.models.Publishing(*args, **kwargs)[source]

For when you don’t need date based publishing (using DatePublishing) this abstract model provides the same API.

For better results, this should be combined with PublishingQuerySet.

is_published = None

BooleanField deciding whether or not the object is available on the site. Defaults to False.

class helpfulfields.models.SEO(*args, **kwargs)[source]

Abstract model for extending custom models with SEO fields

Attempts to maintain compatibility with django CMS, in terms of access methods, but not underlying objects (as django CMS has Title objects).

get_meta_description()[source]

utility method for django CMS api compatibility

Returns:the meta_description field’s value
Return type:unicode string
get_meta_keywords()[source]

utility method for django CMS api compatibility

Returns:the meta_description field’s value
Return type:unicode string
get_page_title()[source]

utility method for django CMS api compatibility

Returns:the meta_title field’s value
Return type:unicode string
meta_description = None

a CharField for storing the description sometimes used in Search Engines. Defined with a max_length of 255.

meta_keywords = None

a CharField for storing a bunch of keywords. Not used by many (any?) Search engines now, but provided for historical completeness, and API compatibility with django CMS. Defined with a max_length of 255.

meta_title = None

a CharField for storing the page’s title. Defined with a max_length of 255.

class helpfulfields.models.SoftDelete(*args, **kwargs)[source]

I’ve not actually used this yet. It’s just a sketch of something I’d like.

The idea is that nothing should ever really be deleted, but I have no idea how feasible this is at an abstract level.

Warning

This should not be relied on to prevent data loss, as it is very much an incomplete idea right now.

delete(using=None)[source]

Instead of deleting this object, and all it’s related items, we hide remove it softly. This means that currently there will be a lot of pseudo-orphans, because I’ve not yet decided on how to handle them. They’re just hangers-on, really.

Parameters:using – the db router to use.
Return type:None
restore(using=None)[source]

Converts a previously deleted object to it’s restored state, by switching the value in the boolean to False (as opposed to NULL for never-deleted)

Parameters:using – the db router to use.
Return type:None
class helpfulfields.models.Titles(*args, **kwargs)[source]

Abstract model for providing a title + menu title field.

Also supplies a get_menu_title method, which falls back to the title if no menu title is set.

get_menu_title()[source]

utility method for django CMS api compatibility

Returns:the menu_title, or if not set, the title
Return type:unicode string
menu_title = None

Optional CharField for an object, whose max_length is 255, and may be used to represent this object in menus.

title = None

Required CharField for an object, whose max_length is 255.

Project Versions

Previous topic

Documentation index

Next topic

Mixing model querysets

This Page