I solved my stupid problem.

In detail.html only change articulo.categoria_set.all for
articulo.categoria.all

On 25 ago, 13:16, NeoOrion <neoor...@gmail.com> wrote:
> Hi,
>
> I have a problem to show ManyToMany Relationship in my Template.
>
> I have two models:
> class Categoria(models.Model):
>     nombre = models.CharField(max_length=200)
>     descripcion = models.TextField('Categoria del Articulo')
>     def __unicode__(self):
>         return self.nombre
>
> class Articulo(models.Model):
>     categoria = models.ManyToManyField(Categoria)
>     titulo = models.CharField(max_length=200)
>     texto = models.TextField('Categoria del Articulo')
>
> In view I have:
> def index(request):
>     latest_articulos_list = Articulo.objects.all().order_by('-
> pub_date')[:5]
>     return render_to_response('articulos/index.html',
> {'latest_articulos_list': latest_articulos_list})
>
> def detail(request, articulo_id):
>     p = get_object_or_404(Articulo, pk=articulo_id)
>     return render_to_response('articulos/detail.html', {'articulo':
> p})
>
> The problem is in the detail view, in this template i have:
> <h1>{{ articulo.titulo }}</h1>
> <p>{{ articulo.texto }}</p>
> <ul>
> {% for categoria in articulo.categoria_set.all %}
>     <li>{{ categoria.nombre }}</li>
> {% endfor %}
> </ul>
>
> I can see the articulo's information, but not categoria.
> Can somebody help me? Thanks.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to