How to exclude Django Modelform fields


Django tip:

You can use either exclude or fields to impact which fields will be available in the Django admin model forms.

For example:

# models.py

class Child(models.Model):
     name = models.CharField(max_length=200)
     last_name = models.CharField(max_length=200)
     grade = models.CharField(max_length=200)



# admin.py  

@admin.register(Child)
class ChildAdmin(admin.ModelAdmin):
    exclude = ('grade',)

# yields the same result as

@admin.register(Child)
class ChildAdmin(admin.ModelAdmin):
    fields = ('name', 'last_name')