Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # models.py
- class ItemAttribute(models.Model):
- category = models.ForeignKey(Category)
- name = models.CharField(max_length=80)
- class ItemAttributeValue(models.Model):
- product = models.ForeignKey(Item)
- attribute = models.ForeignKey(ItemAttribute, related_name='attribute')
- value = models.CharField(max_length=80)
- # views.py
- def macbook_view_by_id(request, macbook_id):
- characteristics = ItemAttribute.objects.filter(category=3)
- # values = ItemAttributeValue.objects.filter(product=macbook_id)
- return render(request, 'macbook_page.html', \
- {'characteristics': characteristics, 'nbar': 'macbook'})
- #template.html
- {% for characteristic in characteristics %}
- {{characteristic.name}}:{{characteristic.attribute.value}}
- {% endfor %}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement