Skip to content

Latest commit

 

History

History
9 lines (5 loc) · 571 Bytes

overwrite_only_model_form_mixin.md

File metadata and controls

9 lines (5 loc) · 571 Bytes

OverwriteOnlyModelFormMixin +

I have a model that is being shared across many forms. An ugly side effect of this was that if I ever forgot to ensure that the HTML rendered contained exactly the fields defined in the form, django would overwrite the values.

Here’s a mixin that you can add to any ModelForm which will only update values.

Note that this still allows users to update a model field explicitly with a blank.

Source