A
A
Artyom Belousov2017-08-20 15:49:46
Django
Artyom Belousov, 2017-08-20 15:49:46

How to hide a field in the admin in Django?

There is a model:

Model

class Article(models.Model):
    title = models.CharField(verbose_name='Заголовок', max_length=100)
    content = models.TextField(verbose_name='Контент')
    date = models.DateField(verbose_name='Дата публикации')
    image = models.ImageField(verbose_name='Изображение', blank=True, default='default.png')
    short_description = models.CharField(verbose_name='Краткое описание',max_length=300)
    tags = TaggableManager(verbose_name='Теги', blank=True)
    hits = models.PositiveIntegerField()

    def __str__(self):
        return f"{self.title} {self.date}"

    class Meta:
        verbose_name = 'Статья'
        verbose_name_plural = 'Статьи'


How can I disable the hits field in the admin panel? I know, you can set default and just ignore it, but still I want to bring it to mind.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Astrohas, 2017-08-20
@flygrounder

exclude = ['hits']
in the admin class, and you need either default or null=True with blank=True for the field

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question