different fields for add and change pages in admin

前端 未结 9 745
日久生厌
日久生厌 2020-12-05 00:37

I have a django app with the following class in my admin.py:

class SoftwareVersionAdmin(ModelAdmin):
    fields = (\"product\", \"version_number\", \"descrip         


        
9条回答
  •  独厮守ぢ
    2020-12-05 01:06

    This is an old question but I wanted to add that the add_view and change_view methods can be modified for this purpose:

    class SoftwareVersionAdmin(ModelAdmin):
         ...
         def add_view(self,request,extra_content=None):
             self.exclude = ('product','version_number',)
             return super(SoftwareVersionAdmin,self).add_view(request)
    
         def change_view(self,request,object_id,extra_content=None):
             self.exclude = ('product','description',)
             return super(SoftwareVersionAdmin,self).change_view(request,object_id)
    

提交回复
热议问题