Guest User

Untitled

a guest
Feb 23rd, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.55 KB | None | 0 0
  1. class Section(models.Model):
  2. name = models.CharField(max_length=255, blank=False, null=True,)
  3.  
  4. class Product(models.Model):
  5. name = models.CharField(max_length=255, blank=False, null=True,)
  6. section = models.ForeignKey(Section,on_delete=models.CASCADE)
  7.  
  8. context['products'] = Product.objects.select_related('section').order_by('section')
  9.  
  10. {% regroup products by section as products_by_section %}
  11.  
  12. {% for section in products_by_section %}
  13. {{ section.grouper}}
  14. {% for product in section.list %}
  15. {{ product }}
  16. {% endfor %}
  17. {% endfor %}
Add Comment
Please, Sign In to add comment