Django Permissions

I would like to have a more detailed resolution in my Django project, but cannot decide which application to use. I have something like:

class Item(models.Model): name = models.CharField(max_length=64, unique=True) description = models.CharField(max_length=128, default='') logo = ImageField(upload_to=/tmp, blank=True, null=True) 

Now, with standard Django permissions, I have the opportunity to choose between adding, changing and deleting, what I want to have is an extended change permission, to offer the ability to give group rights only to change the logo, for example, but prohibit the same group. to change the item description. I don’t want or need a relationship between the user and the record, but just provide the opportunity for different groups to edit individual fields of the model using the standard administrator interface. I'm not even sure what I'm talking about object permission?

Does anyone know what is best to use or how do I implement it myself? I could also imagine that read-only users have access to / read everything, but it's impossible to change them, and it's impossible.

Thanks for any help.

+7
source share
3 answers

The most flexible way:

As far as I can see, this is the only way to achieve what you want, but it also requires a lot of work.

+7
source

One easy way to achieve this is to create many ModelAdmin for the same model (one for each β€œgroup”). To do this, you need to create Proxy models for each "group" as follows:

models.py

 class Item(models.Model): name = models.CharField(max_length=64, unique=True) description = models.CharField(max_length=128, default='') logo = ImageField(upload_to=/tmp, blank=True, null=True) class ItemGroup1(Item): class Meta: proxy = True 

admin.py

 class ItemAdmin(models.ModelAdmin): ... class ItemGroup1Admin(models.ModelAdmin): readonly_fields = ('logo', 'description') 

And then you just need to set the permissions of group 1 to have access only to ItemGroup1 , etc.

See this post for more information: Using proxy models to configure Django admin

+1
source

If you want to handle these kinds of things outside your admin site, check out django-logical-rules , where you can write your rules in python and access them from views or inside a template;

0
source

All Articles