python - recover the questions related to responses retrieve to ManyToMany -
first model contains questions , answers pages manage issues.
my models.py
class question(models.model): label = models.charfield(max_length=30) def __str__(self): return self.label class page(models.model): title = models.charfield(max_length=30) def __str__(self): return self.title class reply(models.model): page = models.manytomanyfield(page) question = models.foreignkey(question) user = models.foreignkey(personne) answer = models.charfield(max_length=30) creationdate = models.datetimefield(default=datetime.now()) def __str__(self): return str(self.answer)
so managed retrieve answers each page 1 page equal to: 1 visit another: visit 2 etc ... (i go share screenshot)
i managed retrieve answers each pages fail see questions corresponding each response page!
this views.py
def reply(request): replies = reply.objects.all() questions = question.objects.all() logged_user = get_logged_user_from_request(request) pages = page.objects.all() form = replyform(request.get) personnes = personne.objects.all() if logged_user: if len(request.get) > 0: form = replyform(request.get) if form.is_valid(): form.save(commit=true) return httpresponseredirect('/reply') else: return render_to_response('polls/reply.html', {'personnes': personnes, 'replies': replies, 'questions': questions,'pages':pages, 'form': form}) else: form = replyform() return render_to_response('polls/reply.html', {'personnes':personnes, 'replies': replies, 'questions': questions, 'pages':pages, 'form': form}) else: return httpresponseredirect('/login')
and finish template reply.html
{% reply in replies %}<br> <br>{{ reply.user }} {{ reply.question }} - {{ reply.answer }} (dans la :{% page in reply.page.all %} {{ page }}) {% endfor %} {% endfor %} <hr> {% page in pages %}<hr> {{ page }}: <br>{{ page.reply.question_set }} : {{ page.reply_set.all }} {% endfor %}
how possible retrieve issues here? manage recover questions every answer not every visit
the questions not displayed each response in each visit
what call in template this? or add line in views.py ?
** edit :**
edit : add screen shot of result right now
template :
{% reply in replies %}<br> <br>{{ reply.user }} {{ reply.question }} - {{ reply.answer }} (dans la :{% page in reply.page.all %} {{ page }}) {% endfor %} {% endfor %} <hr> {% page in pages %}<hr> {{ page }}: <br>{% reply in page.reply_set.all %}<br> {{ reply.question }} (author : {{ reply.user }}) {% endfor %} {% endfor %}
{% reply in replies %}<br> <br>{{ reply.user }} {{ reply.question }} - {{ reply.answer }} (dans la :{% page in reply.page.all %} {{ page }}) {% endfor %} {% endfor %} <hr> {% page in pages %}<hr> {{ page }}: <br>{% each_reply in page.reply_set.all }}{{each_reply.question}}{% endfor %} : {{ page.reply_set.all }} {% endfor %}
Comments
Post a Comment