Reputation: 33573
In Django, you get the model editor for free in the admin/
pages. This all works fine, but I have a few fields in my models that are generated and should never be touched by anybody through a form.
How can I exclude them from these admin/.../change/
forms?
I added exclude to the ModelAdmin
:
class exampleAdmin(admin.ModelAdmin):
exclude = ('field',)
class example(models.Model):
field = models.CharField(max_length = 100)
Upvotes: 1
Views: 69
Reputation: 55448
I have a few fields in my models that are generated and should never be touched by anybody through a form.
You may also use editable=False
on your model's field
If False, the field will not be displayed in the admin or any other ModelForm. They are also skipped during model validation. Default is True.
class Example(models.Model):
field = models.CharField(max_length=100, editable=False)
Upvotes: 2
Reputation: 2088
You have to register
your exampleAdmin
to take effect. In your admin.py
add admin.site.register(example, exampleAdmin)
Upvotes: 3