How to exclude Django Modelform fields

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')

posted @ 2022-10-28 15:59  悠然采  阅读(26)  评论(0编辑  收藏  举报