任务可以分配一组,也可以提供用户列表。
如果有人登录系统。检查任务状态和组以及görevli(列表)。如果列表中的用户或user.group.all中的组,则显示过滤的列表。
我没有进行过滤查询
# todotask = Task.objects.filter(state='to-do').filter(grup__in=request.user.groups.all)
class Task(models.Model):
class Meta:
verbose_name = _("Görev")
verbose_name_plural = _("Görevler")
STATUSES = (
('to-do', _('Yapılacak')),
('in_progress', _('Yapılıyor')),
('blocked', _('Durduruldu')),
('done', _('Tamamlandı')),
('dismissed', _('İptal Edildi')),
('late', _('Gecikti'))
)
PRIORITIES = (
('00_low', _('Düşük')),
('10_normal', _('Orta')),
('20_high', _('Önemli')),
('30_critical', _('Çok Önemli')),
('40_blocker', _('Engelleyici'))
)
title = models.CharField(_("Başlık"), max_length=200)
partner = models.ForeignKey(Partner, blank=True, null=True, on_delete=models.PROTECT,verbose_name="Dış Ortak")
proje = models.ForeignKey(Proje, blank=True, null=True, on_delete=models.PROTECT, verbose_name="Proje")
description = RichTextField("Açıklama", max_length=2000, null=True, blank=True)
resolution = RichTextField("Sonuç", max_length=2000, null=True, blank=True)
deadline = models.DateField(_("Teslim Tarihi"), null=True, blank=True, default=datetime.now() + timedelta(days=1))
grup = models.ForeignKey(Group, related_name='task_assigned', verbose_name=_('Atanan Grup'),
on_delete=models.SET_NULL, null=True, blank=True)
gorevli = models.ManyToManyField(User, verbose_name="Atanan Görevliler", related_name='tasks_assigned', null=True,
blank=True)
state = models.CharField(_("Durum"), max_length=20, choices=STATUSES, default='to-do')
priority = models.CharField(_("Öncelik"), max_length=20, choices=PRIORITIES, default='10_normal')
created_by = models.ForeignKey(settings.AUTH_USER_MODEL, related_name='users_created', verbose_name=_('created by'),
on_delete=models.SET_NULL, null=True)
created_at = models.DateTimeField(_("Oluşturulma Zamanı"), auto_now_add=True, editable=False)
last_modified = models.DateTimeField(_("Son Güncelleme"), auto_now=True, editable=False)
此过滤器必须返回我的列表。
todotask = Task.objects.filter(state='to-do')
答案 0 :(得分:0)
def get_queryset(self, request):
pusers = []
liste = []
projeler = Proje.objects.all()
for proje in projeler:
print(proje.title)
if (proje.grup is not None):
pusers.append(list(proje.grup.user_set.all()))
pusers.append(list(proje.gorevli.all()))
if request.user.username in str(pusers):
liste.append(proje)
qs = super().get_queryset(request)
gsm = list(liste)
newqs = Proje.objects.filter(id__in=[o.id for o in gsm])
if request.user.is_superuser:
return qs
else:
return newqs`enter code here`