Django: Adding Permission to an Specific Model Instance
Asked Answered
U

3

13

I am looking for the best way to implement user permissions to allow users to edit specific model instances.

For instance, I have such two models:

model RadioChannel(models.Model):
    name = models.CharField(max_length=150, unique= True)
    number = models.IntegerField( unique= True)

model ProgramSchedule(models.Model):
    channel = models.ForeignKey("RadioChannel")
    name = models.CharField(max_length=150, unique= True)
    start_time = models.DateTimeField()

Now my Operators are my build-in Django users. I want to make groups for these users so that they can only add/remove/edit ProgramSchedules that are allowed. In addition I want to add groups to these users to the admin panel.

Thanks.

Ugaritic answered 2/11, 2010 at 8:54 Comment(0)
C
12

You are looking for an object permission implementation. A good comparison is here: http://djangopackages.com/grids/g/perms/

Shameless plug: Heres my fork of a very popular per-object permission app: http://github.com/azizmb/django-authority

Cutpurse answered 2/11, 2010 at 9:9 Comment(1)
Sounds good ! Did you document also how to add permissions from python code ? That was something I kind of missed in the original version of the doc.Ahmad
U
5

If I am getting you correct, what you need to implement is called row level permissions in Django. Have a look at this if it helps. http://code.djangoproject.com/wiki/RowLevelPermissionsDeveloper

Untried answered 2/11, 2010 at 9:44 Comment(1)
This allows you to set the permissions on the row level i.e. a specific instance of the model.Untried
C
5

I would recommend using Django Guardian for object-level permissions.

Cuddle answered 30/7, 2014 at 23:6 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.