django - Why does BaseModelForm update ALL fields, despite documentation saying it does not? Is this a bug? -


i'm working on django project legacy db, using formset edit set of rows. there fields in db don't want django update, although need them in model. in other words, want them treated read-only fields. thus, happy read documentation on saving model formsets, states:

"when fields missing form (for example because have been excluded), these fields not set save() method. can find more information restriction, holds regular modelforms, in selecting fields use."

https://docs.djangoproject.com/en/1.8/topics/forms/modelforms/#saving-objects-in-the-formset

indeed, when forms.model.basemodelform.save() invoked, calls forms.model.save_instance(), nicely passing in form fields. calls instance.save() without passing along update_fields!! , model fields included in update query :-(

as test, modified forms.model.save_instance() pass fields:

instance.save(update_fields=fields) 

and voila - model saves fields listed form.

i'm hoping more involved in django project can tell me if bug, or documentation issue? should submit bug report? missing - there other way should enforcing "read only" on fields?

using django1.8 , python3.4

i'm not sure why think behaviour contradicts documentation, or why need pass along fields update. instance has unchanged data; django update rest of fields form, , save whole thing.


Comments