Form Classes and Mixins¶
UserSavable
¶
New in version 0.7.
- class djem.forms.UserSavable[source]¶
A mixin for a Django
ModelForm
that adds support for models using theAuditable
model mixin. It handles providing a user instance to the model’ssave()
method when the form’s ownsave()
method is called, as is required byAuditable
.This mixin assumes the presence of a
self.user
attribute that thesave()
method can use. It is designed for use by forms that already accept and store a known user, e.g. as a constructor argument.For a form that provides the same customisation of the
save()
method and includesuser
as a constructor argument, seeAuditableForm
.
AuditableForm
¶
Changed in version 0.7: Renamed from CommonInfoForm
. The old name is still available for backwards compatibility, but is considered deprecated.
- class djem.forms.AuditableForm(*args, user=None, **kwargs)[source]¶
A Django
ModelForm
that is customised to support models using theAuditable
model mixin. It handles providing a user instance to the model’ssave()
method when the form’s ownsave()
method is called, as is required byAuditable
. It also adds auser
keyword argument to the constructor so thesave()
method has a known user to work with. Theuser
argument is required if the field is bound, otherwise it is optional. The given user is stored in theuser
instance attribute. Subclasses may choose to use the known user for their own purposes.For a mixin that provides the same customisation of the
save()
method without the extra constructor argument (e.g. for use by forms that already accept and store a known user), seeUserSavable
.- user¶
The user model instance provided to the constructor on instantiation. May be
None
on unbound forms.