Z
Z
zkweb2016-04-29 16:04:28
Django
zkweb, 2016-04-29 16:04:28

How to grant rights to a group?

I'm new to Django, please don't kick me :) I
have a question regarding access rights, viewing, editing

class Netsch(models.Model):
    user = models.ForeignKey(User, verbose_name = u"Пользователь")#
    month = models.SmallIntegerField(verbose_name = u"Месяц", choices=MONTH_CHOICES, blank=True,null=True)#
    year = models.SmallIntegerField(verbose_name = u"Год", choices=YEAR_CHOICES, blank=True,null=True)# 
    
class Netschlistwork(models.Model):
    netsch = models.ForeignKey(Netsch, verbose_name = u"ID работы")#   
    limitation = models.CharField(max_length=100,verbose_name = u"Срок исполнения")#
    index = models.TextField(u"Показатель")#
    resources = models.TextField(u"Ресурсы")#
    rating = models.CharField(max_length=100,verbose_name = u"Критерии оценки",blank=True)#
    comment = models.TextField(u"Комментарии",blank=True)#
    type = models.IntegerField(verbose_name = u"Тип", choices=TYPE_CHOICES,default=1)#
    status = models.IntegerField(verbose_name = u"Статус", choices=STATUS_CHOICES,default=1)#

There are 5 groups: superadmin, moderator of the wholesale department, managers of the wholesale department, moderator of the purchasing department, purchasing managers,
Made sure that each user from the group - editors saw only their own posts
def get_queryset(self, request):        
        if request.user.is_superuser:
            qs = Netsch.objects.filter()
            return qs
        else:   
            # остальным пользователям - пока сделал так \
            qs = Netsch.objects.filter(user=request.user.id)
            return qs

I need to do the following: so that a user from the moderator group of the purchasing department can see and edit all the records of the group purchasing managers
Please write the code for an example. How do I tell the moderator of the purchasing department group that he can see and edit the group purchasing managers
PS also installed the guardian module
Thank you! Forgive me if I wrote crooked \

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anatoly Scherbakov, 2016-04-29
@zkweb

1. Where is the get_queryset function? In the model class?
2. About django-guardian - I'm not sure if you need it. And these tasks - are really solved by means of get_queryset, but in representations. You can inherit them from ListView, UpdateView, and override get_queryset using self.request.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question