Reputation: 2686
I want to have the Django admin use a custom form field for the input of some fields.
Until now I made a custom model field that has the form field bound to it which works great but it introduces an unecessary model field that does not add any benefit.
I guess it can be done somehow using a custom admin form (see http://docs.djangoproject.com/en/dev/ref/contrib/admin/#adding-custom-validation-to-the-admin) but I couldn't figure out how to do it.
Upvotes: 10
Views: 9164
Reputation: 239200
class MyModelForm(forms.ModelForm):
my_field = MyCustomFormField()
class Meta:
model = MyModel
class MyModelAdmin(admin.ModelAdmin):
form = MyModelForm
Upvotes: 8