Django Admin: Using a custom widget for only one model field

Create a custom ModelForm for your ModelAdmin and add ‘widgets’ to its Meta class, like so:

class StopAdminForm(forms.ModelForm):
  class Meta:
    model = Stop
    widgets = {
      'field_name': ApproveStopWidget(),
    }
    fields="__all__"

class StopAdmin(admin.ModelAdmin):
  form = StopAdminForm

Done!

Documentation for this is sort of non-intuitively placed in the ModelForm docs, without any mention to it given in the admin docs. See: Creating forms from models

Leave a Comment