I have troubles with filtering objects . The objects are displaying in all lists but I have set Foreign key for specific list . Is there any solutions ?
models.py
class Lists(models.Model):
title = models.CharField(max_length=200)
class ListsItem(models.Model):
date = models.DateTimeField(default=datetime.now,blank=True)
title = models.CharField(max_length=200)
main_list=models.ForeignKey(Lists, on_delete=models.SET_NULL, null=True)
views.py
lists = Lists.objects.order_by('date')
listitems = ListsItem.objects.filter(main_list__in=lists).order_by('date')
template
{% if lists %}
{% for list in lists %}
{{list.title}}
{% if listitems %}
{% for listitem in listitems %}
{{listitem.title_item}}
{% endfor %}
{% endif %}
{% endfor %}
{% endif %}