Django admin: exclude field on change form only

后端 未结 4 1619
甜味超标
甜味超标 2020-12-13 16:23

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

4条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-13 16:50

    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)
    

提交回复
热议问题