viewhelpers.formview.create_update_view_mixin — Create and update view mixins¶
Mixin class for Update and Create views.
You should import this class with
from django_cradmin import viewhelpers, and refer to it using
The model class.
If you set
roleid_field, we will remove that field from the form.
roleid_fieldhandling also works for GenericForeignKey fields (removes the content type and object pk field from the form).
Get the verbose name of the model.
Must be called in
get_context_data()in subclasses to add the required context data.
Parameters: context – The template context data.
save_object()to set automatic attributes for the object before it is saved.
- obj – The object you are about to save.
- form – The cleaned form.
Save the object. You can override this to customize how the form is turned into a saved object.
Make sure you call
superif you override this (see the docs for the commit parameter). If you do not, you will loose the automatic handling of obj:.roleid_field.
Parameters: commit (boolean) – If this is
False, the object is returned unsaved. Very useful when you want to manipulate the object before saving it in a subclass.
Returns: The saved object.
If the form is valid, save the associated model.
Called after the form has been successfully saved. The
objectis the saved object.
Does nothing by default, but you can override it if you need to do something extra post save.
Override this to provide a success message.
objis the saved object.
Called after the form has been saved, and after
form_saved()has been called.
objis the saved obj.
You can override this to add multiple messages or to show messages in some other way.
Seralize for preview.
Defaults to serializing the object as JSON using
django.core.serializers. You can safely override this, but you will also have to override
Deseralize a preview serialized with
You must override this and
serialize_preview()- they work together to send the preview to the preview View.
Get the session key used for preview. You should not need to override this.
Unlike the default implementation of this method from
django_cradmin.viewhelpers.formbase.PreviewMixin, we use the model class module and name as the session key. This is simply because we do not want it to matter if you fetch preview data from create or update views for the same model (to simplify implementing preview views).