Advertisement
Guest User

Untitled

a guest
Jun 16th, 2015
238
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. # models.py
  2. class ItemAttribute(models.Model):
  3. category = models.ForeignKey(Category)
  4. name = models.CharField(max_length=80)
  5.  
  6. class ItemAttributeValue(models.Model):
  7. product = models.ForeignKey(Item)
  8. attribute = models.ForeignKey(ItemAttribute, related_name='attribute')
  9. value = models.CharField(max_length=80)
  10.  
  11. # views.py
  12. def macbook_view_by_id(request, macbook_id):
  13. characteristics = ItemAttribute.objects.filter(category=3)
  14. # values = ItemAttributeValue.objects.filter(product=macbook_id)
  15. return render(request, 'macbook_page.html', \
  16. {'characteristics': characteristics, 'nbar': 'macbook'})
  17.  
  18. #template.html
  19. {% for characteristic in characteristics %}
  20. {{characteristic.name}}:{{characteristic.attribute.value}}
  21. {% endfor %}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement