Dynamic fields in Django Admin

后端 未结 9 1480
失恋的感觉
失恋的感觉 2020-12-05 05:18

I want to have additional fields regarding value of one field. Therefor I build a custom admin form to add some new fields.

Related to the blogpost of jacobian 1 thi

9条回答
  •  佛祖请我去吃肉
    2020-12-05 05:43

    Here is a solution to the problem. Thanks to koniiiik i tried to solve this by extending the *get_fieldsets* method

    class ProductAdmin(admin.ModelAdmin):
        def get_fieldsets(self, request, obj=None):
            fieldsets = super(ProductAdmin, self).get_fieldsets(request, obj)
            fieldsets[0][1]['fields'] += ['foo'] 
            return fieldsets
    

    If you use multiple fieldsets be sure to add the to the right fieldset by using the appropriate index.

提交回复
热议问题