[Django]-Hide Model Property from Django admin and set Its Value Manually

3👍

You can mark the field as read-only but still have it visible in the admin, or completely exclude it.

class MyModel(models.Model):
    field1 = models.CharField(max_length=20) # this is editable
    field2 = models.CharField(max_length=20, editable=False) # this is not

or

@admin.register(MyModel)
class MyModelAdmin(admin.ModelAdmin):
    exclude = ['field2']

If you’re using a custom model form in the admin, just don’t include the field in the fields attribute.

0👍

As far as I remember there are a lot of ways to do this, with the fields attribute on Meta you can hide or select which fields to show.

check This example

Leave a comment