Answer the question
In order to leave comments, you need to log in
Is it possible to do a django-like query in jinja2?
Hello everyone, is it possible to perform a similar selection in jinja2 (django)?
Or is it necessary to make a selection in views and then pass it to html ?
I want to do like this:
{% for p in products %}
<h1>{{ p.product_name }}</h1>
<h4>{{ colors.filter(s = p.product_name) }}</h4>
{% endfor %}
class Products(models.Model):
product_name = models.CharField(max_length=50,default='none',verbose_name='Название')
about = models.CharField(max_length=50,default='none',verbose_name='Информация')
class Meta:
verbose_name = "Продукт"
verbose_name_plural='Продукты'
def __unicode__(self):
return self.product_name
class Colors(models.Model):
s = models.ForeignKey(Products)
white = models.BooleanField(default=False)
yellow= models.BooleanField(default=False)
green= models.BooleanField(default=False)
class Meta:
verbose_name_plural='Цвета'
### 100+ colors
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question