Django: Adding Permission to an Specific Model Ins

2020-07-03 03:59发布

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.

3条回答
做个烂人
2楼-- · 2020-07-03 04:43

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

查看更多
男人必须洒脱
3楼-- · 2020-07-03 04:43

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

查看更多
ら.Afraid
4楼-- · 2020-07-03 04:50

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

查看更多
登录 后发表回答