Dynamic fields in Django Admin

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.

Leave a Comment