Devang Padhiyar
Devang Padhiyar

Reputation: 3707

How to add django admin read-only permissions?

How to add read-only permissions in Model in django?

By default there are three permissions available for users Can add, Can delete, Can change.

How to add Can read permission in Model in Django.

Upvotes: 1

Views: 4925

Answers (2)

Eyap
Eyap

Reputation: 694

First solution

You didn't specify your django version, but i suppose you are in Django 1.x, as starting django 2.x there are four default permissions : add, change, delete, and the new one view, which is the one your are interested in. So a first solution (maybe not the easiest), is to upgrade to django 2.x, and use the view permission.

Second solution

Second solution, you can add the permissions you want to use for each model in the Meta, as described in the docs : permissions.

permissions = (("can_read", "Can read"),)

Side note

Note that you can also edit the default permissions by model, by using the default_permissions key. See default-permissions.

Upvotes: 1

Deniz Kaplan
Deniz Kaplan

Reputation: 1609

As documentation custom permissions indicates, you can define custom permissions on model's meta class.

class Task(models.Model):
...
class Meta:
    permissions = (
        ("change_task_status", "Can change the status of tasks"),
        ("close_task", "Can remove a task by setting its status as closed"),
    )

Upvotes: 0

Related Questions