Add a mixin for updating models with a ModelForm
Review Request #7494 — Created July 6, 2015 and submitted — Latest diff uploaded
UpdateFormMixinis a mixin for a
WebAPIResourcethat 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.
ModelFormcan take an
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
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
Used this in a Review Board API resource.