Add a mixin for updating models with a ModelForm

Review Request #7494 — Created July 6, 2015 and submitted — Latest diff uploaded

Information

Djblets
release-0.9.x
1cbef5d...

Reviewers

The UpdateFormMixin is a mixin for a WebAPIResource that allows a
resource to specify a form class (which should be a subclass of
django.forms.ModelForm) to use for creating and updating of model
instances. This allows the resource that are very basic wrappers around
models to have their logic further simplified.

This mixin is required for allowing partial updating of models.
Traditionally, a ModelForm can take an instance parameter
specifying an already existing model instance to update, but will still
require all required field to specified in the form data. This mixin
takes care of that by extracting missing form data from the instance
and inserting it into the form data in the proper format (such as
setting it to be a list of primary keys in the case of a
ModelMultipleChoiceField).

This mixin also allows resources to specify special functions for
parsing values out of the recieved form data. This is useful, e.g., for
automatically converting human-readable values accepted by the API to
the value the database expects for a ChoiceField.

Used this in a Review Board API resource.