Search code examples
pythondjangodjango-admin

Django admin: exclude field on change form only


If there a way to detect if information in a model is being added or changed.

If there is can this information be used to exclude fields.

Some pseudocode to illustrate what I'm talking about.

class SubSectionAdmin(admin.ModelAdmin):
    if something.change_or_add = 'change':
        exclude = ('field',)
    ...

Thanks


Solution

  • class SubSectionAdmin(admin.ModelAdmin):
        # ...
        def change_view(self, request, object_id, extra_context=None):       
            self.exclude = ('field', )
            return super(SubSectionAdmin, self).change_view(request, object_id, extra_context)