Form Classes and Mixins¶
UserSavable¶
New in version 0.7.
-
class
djem.forms.UserSavable[source]¶ A mixin for a Django
ModelFormthat adds support for models using theAuditablemodel 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.userattribute 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 includesuseras 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
ModelFormthat is customised to support models using theAuditablemodel 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 auserkeyword argument to the constructor so thesave()method has a known user to work with. Theuserargument is required if the field is bound, otherwise it is optional. The given user is stored in theuserinstance 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
Noneon unbound forms.
-