[Django]-Django admin add_view only renders up until change_view is displayed for first time

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

Leave a comment