Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Section(models.Model):
- name = models.CharField(max_length=255, blank=False, null=True,)
- class Product(models.Model):
- name = models.CharField(max_length=255, blank=False, null=True,)
- section = models.ForeignKey(Section,on_delete=models.CASCADE)
- context['products'] = Product.objects.select_related('section').order_by('section')
- {% regroup products by section as products_by_section %}
- {% for section in products_by_section %}
- {{ section.grouper}}
- {% for product in section.list %}
- {{ product }}
- {% endfor %}
- {% endfor %}
Add Comment
Please, Sign In to add comment