4π
β
It isnβt safe to modify self.fields
, self.fieldsets
and self.readonly_fields
like this. You are changing them for future requests as well as the current one.
Instead of modifying these attributes in the add_view
and change_view
methods, you can override the get_fields
, get_fieldsets
, and get_readonly_fields
instead. If the obj
is None, then you are adding an object. For example:
def get_fields(self, request, obj=None):
if obj is None:
return [<fields for add view>]
else:
return [<fields for change view>]
π€Alasdair
Source:stackexchange.com