[Fixed]-How do you add a non-editable field to a custom admin form in Django

18👍

You need to remove the non-editable field from your class form list of fields :

class HelpDeskModelForm(forms.ModelForm):

    class Meta:
      model = HelpDesk
      fields = [
          #"help_num",
          "help_types",
           ...
          "help_summary"
          ]

And keep the read-only fields in the ModelAdmin like you did :

class HelpDeskModelAdmin(admin.ModelAdmin):
    readonly_fields=('help_num',)
    form = HelpDeskModelForm

Leave a comment