Answer the question
In order to leave comments, you need to log in
How to make an ORM request?
there are these models:
class Team(models.Model):
def __str__(self):
return self.teamname
teamname = models.CharField(max_length = 64, verbose_name='Название команды')
member = models.ManyToManyField(User, verbose_name='Члены команды')
class Task(models.Model):
def __str__(self):
return self.tasktitle
STATUS_CHOICE = (
("new", "Новый"),
("inprogress", "В процессе"),
("done", "Готово"),
)
TYPE_CHOICE = (
('nw', 'Новость'),
('tk', 'Задача'),
('nt', 'Уведомление')
)
tasktitle = models.CharField(max_length = 128, verbose_name='Заголовок')
description = models.TextField(max_length = 100000, verbose_name='Описание')
datetoresolve = models.DateField(verbose_name='Срок выполнения')
status = models.CharField(choices = STATUS_CHOICE, max_length = 10, blank=True, verbose_name='Статус')
tasktype = models.CharField(choices = TYPE_CHOICE, max_length = 2, default='nt', verbose_name='Тип записи')
resposiblePerson = models.ManyToManyField(User, blank=True, verbose_name='Ответственный сотрудник')
responsibleTeam = models.ManyToManyField(Team, blank=True, verbose_name='Ответственная команда')
watcher = models.ManyToManyField(User, blank=True, verbose_name='Наблюдатель', related_name='watcher_p')
helper = models.ManyToManyField(User, blank=True, verbose_name='Помогающий', related_name='helper_p')
performer = models.ManyToManyField(User, blank=True, verbose_name='Исполнитель', related_name='peformer_p')
Task.objects.filter(resposiblePerson__username="gennady")
Answer the question
In order to leave comments, you need to log in
from functools import reduce
import operator
from django.db.models import Q
user = request.user
filters = (
Q(resposiblePerson=user),
Q(responsibleTeam__member=user),
Q(watcher=user),
Q(helper=user),
Q(performer=user),
)
tasks = Task.objects.filter(reduce(operator.or_, filters))
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question