Jump to >


Mixins for integrating a web API resource with a form.

class UpdateFormMixin[source]

Bases: object

A mixin for providing the ability to create and update using a form.

A WebAPIResource class using this mixin must set the form_class attribute to a ModelForm instance that corresponds to the model being updated.

Classes using this mixin can provide methods of the form parse_<field_name>_field to do parsing of form data before it is passed to the form. Parser methods should be of the form:

def parse_some_field(self, value, request, **kwargs):
    # ...

These methods may return either a single value or a list of values (in the case where the corresponding field expects a list of values, such as a django.forms.ModelMultipleChoiceField).

The create_form() methods should be used to create new form instances. A form created this way can be given an optional instance argument to allow for updating the instance. Any fields missing from data (but appearing in the form_class’s fields attribute) will be copied over from the instance.

form_class = None[source]

The form class. This should be a subclass of

create_form(data, request, instance=None, **kwargs)[source]

Create a new form and pre-fill it with data.

  • data (dict) – The request data to pass to the form.
  • request (django.http.HttpRequest) – The HTTP request.
  • instance (django.db.models.Model) – The instance model, if it exists. If this is not None, fields that appear in the form class’s fields attribute that do not appear in the data dict as keys will be copied from the instance.
  • **kwargs (dict) – Additional arguments. These will be passed to the resource’s parser methods.

The form with data filled.

Return type: