L
L
Legalas612019-10-13 21:11:29
Django
Legalas61, 2019-10-13 21:11:29

How to hide or make it impossible to edit input in the admin?

Made model with user = models.ForeignKey(). It is used by all users/groups who have rights to create a post, but it needs to be editable only by superusers (only 1 input from the entire form). Where should I write the check? As far as I understand, then models is work with the database, it turns out that you need to write in admin.py?

class Post(models.Model):
    user = models.ForeignKey(
        User,
        verbose_name="Пользователь",
        on_delete=models.CASCADE,
        default = User.id)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Ruslan Gilfanov, 2019-10-13
@Legalas61

Django documentation / The Django admin site / ModelAdmin options / ModelAdmin.readonly_fields

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question