Answer the question
In order to leave comments, you need to log in
How to properly attach annotation to queryset?
There are models:
class answer(models.Model):
name = models.CharFIeld("Name", max_length=10)
class message(models.Model):
message = models.CharField("Message", max_length=50)
look = models.BooleanField(default=False)
answer = models.ForeignKey(answer)
message(look=False, answer=(к текущему объекту итерции answer)) то True Иначе False
for item in answer.objects.all(): # filter(...)
messages_ = message.objects.filter(answer=item)
if messages_ .count():
item.look_bool= True
else:
item.look_bool= False
if messages_ .filter(view=False).count():
item.new_bool= True
else:
item.new_bool= False
messages_ = message.objects.filter(answer=item)
django.views.generic.ListView), and there, if True, display an additional field for answer.
answ = answer.objects.all() # filter(...)
answ.annotate(
count_message=Count('message')
).annotate(
new_message=Count('message')
).filter(
message__look=False
)
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question