class Categoria(models.Model):
DEFAULT_CATHEGORY = 0
nome = models.CharField(max_length=255, null=False, default='0')
def __unicode__(self):
return self.nome
class Produto(models.Model):
nome = models.CharField(max_length=255, null=False)
pontos_na_compra = models.DecimalField(decimal_places=4, max_digits=10, default=0)
pontos_na_troca = models.DecimalField(decimal_places=4, max_digits=10, default=0)
foto = models.ImageField(upload_to=get_image_path, blank=True, null=True)
categoria = models.ForeignKey(
Categoria,
default=Categoria.DEFAULT_CATHEGORY
)
def __unicode__(self):
return "%s, %s" % (self.nome, self.codigo_depara)
show CATEGORIA.nome
for each PRODUTO in LIST OF PRODUCTS IN CATEGORIA do:
show PRODUTO.nome
show PRODUTO.pontos_na_compra
show PRODUTO.foto
end-for
{% if categorias %}
<ul id="flexisel">
{% for categoria in produto.categoria_set() %}
<li>
# SHOW ALL HERE. HOW?
</li>
{% endfor %}
</ul>
{% else %}
<p id="flexise">
Nenhum produto encontrado!
</p>
{% endif %}
Could not parse the remainder: '()' from 'produto.categoria_set()'
| Request Method: | GET |
|---|---|
| Request URL: | http://127.0.0.1:8000/ |
| Django Version: | 1.9.2 |
| Exception Type: | TemplateSyntaxError |
| Exception Value: | Could not parse the remainder: '()' from 'produto.categoria_set()' |
| Exception Location: | /home/dsbonafe/.virtualenvs/bruno/local/lib/python2.7/site-packages/django/template/base.py in parse, line 516 |
| Python Executable: | /home/dsbonafe/.virtualenvs/bruno/bin/python |
| Python Version: | 2.7.6 |
| Python Path: | ['/home/dsbonafe/Documentos/Projetos/Bruno Mercado/bruno/redewebsite', '/home/dsbonafe/.virtualenvs/bruno/lib/python2.7', '/home/dsbonafe/.virtualenvs/bruno/lib/python2.7/plat-x86_64-linux-gnu', '/home/dsbonafe/.virtualenvs/bruno/lib/python2.7/lib-tk', '/home/dsbonafe/.virtualenvs/bruno/lib/python2.7/lib-old', '/home/dsbonafe/.virtualenvs/bruno/lib/python2.7/lib-dynload', '/usr/lib/python2.7', '/usr/lib/python2.7/plat-x86_64-linux-gnu', '/usr/lib/python2.7/lib-tk', '/home/dsbonafe/.virtualenvs/bruno/local/lib/python2.7/site-packages', '/home/dsbonafe/.virtualenvs/bruno/lib/python2.7/site-packages'] |
| Server time: | Ter, 23 Fev 2016 20:55:39 +0000 |
>
> I try to use
>>
>> {% if categorias %}
>> <ul id="flexisel">
>> {% for categoria in produto.categoria_set() %}
At no time can parentheses be used when referencing variables. The correct way to write this tag would be {% for categoria in produto.categoria_set %}.
Make sure to review the template syntax for accessing context variables and methods: https://docs.djangoproject.com/en/1.9/ref/templates/language/#variables
-James
--
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...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CA%2Be%2BciXoFit4aj1sLmNwwiZ2%3DYg2%2Bz2cp0DuNk-cPxxyn8sikA%40mail.gmail.com.