我有两个查询集的结果,需要将它们放在一起以迭代我的视图。
data = dict()
item = get_object_or_404(Item, pk=pk)
phase = item.phase_set.all()
evaluation = item.evaluation_set.all().exists()
data["timeline"] = phase
....
return render(request, 'item_detail.html', data)
我需要将data["timeline"]
的值和phase
的值放入evaluation
中,如何在evaluation
结果中添加phase
结果?
evaluation
收到true
或false
,如果evaluation
为真,我认为我需要显示相位值
模型阶段
class Phase_History(models.Model): # noqa
date_change = models.DateTimeField('date')
item = models.ForeignKey('Item', on_delete=models.DO_NOTHING)
author = models.ForeignKey('users.UserProfile', on_delete=models.DO_NOTHING)
current = models.BooleanField()
模型评估
class Evaluation(models.Model):
valuator = models.ForeignKey('users.UserProfile', on_delete=models.PROTECT)
item = models.ForeignKey('Idea', on_delete=models.PROTECT)
在我的item_detail.html视图中:
{% for timeline_item in timeline %}
{% if evaluation %}
{{timeline_item.date_change}}
{{timeline_item.author}}
{% endif %}
{% endfor %}
....