Answer the question
In order to leave comments, you need to log in
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)#
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
Answer the question
In order to leave comments, you need to log in
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 questionAsk a Question
731 491 924 answers to any question