Model Mixins and Base Classes¶
CommonInfoMixin
¶
-
class
djem.models.
CommonInfoMixin
[source]¶ CommonInfoMixin
is a model mixin class that provides:- Standard user and datetime fields:
user_created
,user_modified
,date_created
,date_modified
. - An overridden
objects
Manager, an instance of the customCommonInfoManager
that provides access to the customCommonInfoQuerySet
. - Support for Ownership checking on an instance and via
CommonInfoQuerySet
. - A simple default implementation of Object-Level Permissions via ownership checking.
- Standard user and datetime fields:
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 forCommonInfoMixin
model forms.
ArchivableMixin
¶
-
class
djem.models.
ArchivableMixin
[source]¶ ArchivableMixin
is a model mixin class that provides:- An
is_archived
Boolean field, defaulting toFalse
. - An overridden
objects
Manager, an instance of the customArchivableManager
that provides access to the customArchivableQuerySet
. - Two additional managers,
live
andarchived
, with default querysets filtered to unarchived (is_archived == False
) and archived (is_archived == True
) records by default. Both are also instances ofArchivableManager
. - 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 theis_archived
flag. It saves using theupdate_fields
keyword argument, containing theis_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 theis_archived
flag. It saves using theupdate_fields
keyword argument, containing theis_archived
field, whether it was provided to this method or not. If provided, it is extended, not replaced.
- An
See also
ArchivableManager
- The custom Manager exposed by the
objects
,live
andarchived
attributes. ArchivableQuerySet
- The custom QuerySet exposed by
ArchivableManager
.
VersioningMixin
¶
-
class
djem.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 customVersioningManager
that provides access to the customVersioningQuerySet
.
-
exception
AmbiguousVersionError
[source]¶ A subclass of
ModelAmbiguousVersionError
specific to theVersioningMixin
class. Raised when attempting to access theversion
field after it has been atomically incremented.
- A
See also
VersioningManager
- The custom Manager exposed by the
objects
attribute. VersioningQuerySet
- The custom QuerySet exposed by
VersioningManager
.
StaticAbstract
¶
-
class
djem.models.
StaticAbstract
[source]¶ StaticAbstract
is a combination ofCommonInfoMixin
,ArchivableMixin
andVersioningMixin
. It is designed as an abstract base class for models, rather than a mixin itself. It includes all the fields, as well as customobjects
,live
andarchived
managers, and provides access to all the functionality offered by each of the mixins.