Dynamic Forms In Django-admin
I want to make admin add-form dynamic. I want to add few formfields depending on setting in related object. I have something like this: class ClassifiedsAdminForm(forms.ModelForm):
Solution 1:
I've managed to do it using type().
classClassifiedAdmin(admin.ModelAdmin):
defget_form(self, request, obj=None, **kwargs):
adminform = ClassifiedsAdminForm()
fields = adminform.getNewFields()
form = type('ClassifiedsAdminForm', (forms.ModelForm,), fields)
return form
Hope it will help someone.
Post a Comment for "Dynamic Forms In Django-admin"