On Thu, Mar 12, 2009 at 1:47 PM, Fred Chevitarese <fchevitar...@gmail.com>wrote:
> > Hello all ... > It´s my first post on here... > So, i´ve got a little problem when i follow the instructions to create > an app on Django. > I´ve created the Poll like the tutorial, and it´s all ok . > But when i try to put this on a view to show in a template i´ve got > the problem. > > I´m from Brazil so, my models, views and templates can be in > portuguese but i think that´s not a problem ;) > > Let´s see... > Below the Models File ### > #Poll > class enquete(models.Model): > pergunta = models.CharField('Pergunta', max_length = 50) > habilitada = models.BooleanField('Habilitada', default = True) > dataCriacao = models.DateField(verbose_name = 'Criada em', > auto_now = True, auto_now_add = True) > > def __unicode__(self): > return self.pergunta > class Meta: > verbose_name = 'Enquete' > verbose_name_plural = 'Enquetes' > #Choice > class respostaEnquete(models.Model): > idPergunta = models.ForeignKey(enquete) > opcao = models.CharField(verbose_name = u'Opção', max_length = 50) > votos = models.IntegerField(verbose_name = u'Número de votos', > default = 0) > > def __unicode__(self): > return self.opcao > class Meta: > verbose_name = 'Resposta da enquete' > verbose_name_plural = 'Respostas das enquetes' > > ## Now, the views file > > # -*- coding: utf-8 -*- > from django.http import HttpResponse > from django.shortcuts import render_to_response > > from Teccom.conteudo.models import * > def noticiasIndex(request): > #Pegando as notícias ... > noticias = noticia.objects.filter(habilitada = True).all() > #Getting the notices ... > lista = enquete.objects.all() # getting the poll > return render_to_response('principal.html', locals()) > > ## and now, the Template file ;) > > <div id="news"> > {% for enquete in lista %} > > <h1>{{ enquete.pergunta }}</h1> > > {% if error_message %}<p><strong>{{ error_message }}</strong></ > p>{% endif %} > > <form action="/enquete/{{ enquete.id }}/vote/" method="post"> > {% for resposta in enquete.resposta_set.all %} enquete instances do not have a resposta_set. They would have a resposta_set if: 1 - the related model's name was resposta, or if 2 - you specified 'resposta_set' as the related_name argument to the ForeignKey that points to enquete in the model However the related model is named respostaEnquete, and its ForeignKey to enquete (idPergunta) does not have a related_name specified, so the reverse relation accessor in enquete objects is named respostaenquete_set (the related models name, lowercased, plus '_set'). Karen --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---