Using Flatpages with the default admin, I need to change the template field from a text input with to select or radio with predefined choices. It's easy to do this with one of my own apps - just use the choices attribute in the model.
I have tried a few things - I will add details about those attempts later if necessary - but does anyone know a nice way to do this?
Define a custom flatpages ModelAdmin class which inherits from the default one but uses a custom form. On this form, override the field, using the widget you want. Then unregister the flatpages admin and reregister it with your custom class.
from django.contrib.flatpages.admin import FlatPageAdmin, FlatpageForm
class MyFlatpageForm(FlatpageForm):
template = forms.ChoiceField(choices=MY_CHOICES)
class MyFlatPageAdmin(FlatPageAdmin):
form = MyFlatpageForm
admin.site.unregister(FlatPage)
admin.site.register(FlatPage, MyFlatPageAdmin)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With