Model Mixins and Base Classes

CommonInfoMixin

class django_goodies.models.CommonInfoMixin[source]

CommonInfoMixin is a model mixin class that provides:

save(user=None, *args, **kwargs)[source]

Overridden to ensure the user_modified and date_modified fields are always updated. The user argument is required and must be passed a User instance, unless the GOODIES_COMMON_INFO_REQUIRE_USER_ON_SAVE setting is False.

owned_by(user)[source]

Return True if user_created matches the given user, otherwise return False. The user can be given as an id or a User instance.

See also

CommonInfoManager
The custom Manager exposed by the objects attribute.
CommonInfoQuerySet
The custom QuerySet exposed by CommonInfoManager.
CommonInfoForm
A ModelForm subclass to act as a base for CommonInfoMixin model forms.

ArchivableMixin

class django_goodies.models.ArchivableMixin[source]

ArchivableMixin is a model mixin class that provides:

  • An is_archived Boolean field, defaulting to False.
  • An overridden objects Manager, an instance of the custom ArchivableManager that provides access to the custom ArchivableQuerySet.
  • Two additional managers, live and archived, with default querysets filtered to unarchived (is_archived == False) and archived (is_archived == True) records by default. Both are also instances of ArchivableManager.
  • Support for archiving and unarchiving, both at the instance level and in bulk via ArchivableQuerySet.
archive(*args, **kwargs)[source]

Archive this record.

Accepts all arguments of the save method, as it saves the instance after setting the is_archived flag. It saves using the update_fields keyword argument, containing the is_archived field, whether it was provided to this method or not. If provided, it is extended, not replaced.

unarchive(*args, **kwargs)[source]

Unarchive this record.

Accepts all arguments of the save method, as it saves the instance after setting the is_archived flag. It saves using the update_fields keyword argument, containing the is_archived field, whether it was provided to this method or not. If provided, it is extended, not replaced.

See also

ArchivableManager
The custom Manager exposed by the objects, live and archived attributes.
ArchivableQuerySet
The custom QuerySet exposed by ArchivableManager.

VersioningMixin

class django_goodies.models.VersioningMixin[source]

VersioningMixin is a model mixin class that provides:

  • A version field that is automatically incremented on every save.
  • An overridden objects Manager, an instance of the custom VersioningManager that provides access to the custom VersioningQuerySet.
save(*args, **kwargs)[source]

Overridden to ensure the version field is always updated.

exception AmbiguousVersionError[source]

A subclass of ModelAmbiguousVersionError specific to the VersioningMixin class. Raised when attempting to access the version field after it has been atomically incremented.

See also

VersioningManager
The custom Manager exposed by the objects attribute.
VersioningQuerySet
The custom QuerySet exposed by VersioningManager.

StaticAbstract

class django_goodies.models.StaticAbstract[source]

StaticAbstract is a combination of CommonInfoMixin, ArchivableMixin and VersioningMixin. It is designed as an abstract base class for models, rather than a mixin itself. It includes all the fields, as well as custom objects, live and archived managers, and provides access to all the functionality offered by each of the mixins.