Thursday, May 21, 2020

Re: Template Variations title not showing

Hello,

i was able to get the variant to show on the product page with using a form.

I cannot get the variants to display in the cart.

Only difference is my Variation model is a ManyToManyField to the item. I have also changed my variant options to numbers as the dict was expecting an integer and not a string, that is why mine shows 0 not size.

Hope this helps, maybe you can help me get the next peice.

thanks 

                    {% if item.variation_set.sizes %}
                    <select class="form-control" name=0 required>
                        {% for item in item.variation_set.sizes %}
                        <option value="" disabled selected hidden>Select Size</option>
                        <option value="{{ item.name }}">{{ item.name }}</option>
                        {% endfor %}
                    </select>
                    {% endif %}

On Tuesday, May 5, 2020 at 5:12:15 PM UTC-6, Ahmed Khairy wrote:

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 %}

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/1d4f4d2f-7670-40bb-b648-f09b530eaee9%40googlegroups.com.

No comments:

Post a Comment