Hello all,
I have made a variation to an Item class in models.py and I think i got the template syntax right but apparently there are something wrong which i can't figure it out
Here is the model
class Item(models.Model):
title = models.CharField(max_length=100)
description = models.TextField()
price = models.FloatField()
slug = models.SlugField(unique=True)
image = models.ImageField(blank=False, upload_to='approved designs')
def __str__(self):
return self.title
class Meta:
unique_together = ('title', 'slug')
class Variation(models.Model):
item = models.ForeignKey(Item, on_delete=models.CASCADE)
title = models.CharField(max_length=120)
image = models.ImageField(null=True, blank=True)
price = models.FloatField(null=True, blank=True)
def __str__(self):
return self.title
and here is the template
{% if item.variation_set.all %}
<select class='form-control' name='size'>
{% for items in item.variation_set.all %}
<option value='{item.variation|lower}'>{{title.title|capfirst}}</option>
{% endfor %}
</select>
{% endif %}