get_query() function in class AltwordlistView which I refer to as Filter-5 didn't give me the ordered list result that I wanted. So somebody on #django IRC helped me to fix that problem by giving me altword_list() function which I refer to as Filter-8.
You can basically ignore all the other Filter codes but I left it there in case it might help you see what I'm trying to do.
My main focus right now is to connect the Filter-8 code to my template altword_list.html but I don't know how to do it.
http://dpaste.com/1417526/
http://dpaste.com/1417533/
http://dpaste.com/1417534/
* urls.py
from django.conf.urls import patterns, url from navi_polls import views #_______________________________________________________________________________ urlpatterns = patterns('', # ex: /polls/ url(r'^$', views.IndexView.as_view(), name='index'), # ex: /polls/5/ url(r'^specifics/(?P<pk>\d+)/$', views.DetailView.as_view(), name='detail'), # ex: /polls/5/results/ url(r'^(?P<pk>\d+)/results/$', views.ResultsView.as_view(), name='results'), # ex: /polls/5/vote/ url(r'^(?P<word_id>\d+)/vote/$', views.vote, name='vote'), # ex: /polls/5/ url(r'^altword_list/(?P<pk>\d+)/$', views.AltwordlistView.as_view(), name='altword_list'), )
* views.py
from django.http import HttpResponseRedirect from django.shortcuts import render, get_object_or_404 from django.core.urlresolvers import reverse from django.views import generic from django.utils import timezone from navi_polls.models import Word, Altword #_______________________________________________________________________________ class IndexView(generic.ListView): template_name = 'navi_polls/index.html' context_object_name = 'latest_poll_list' def get_queryset(self): # Filter 1 """ Return the last five published polls (not including those set to be published in the future). """ return Word.objects.filter(pub_date__lte=timezone.now() ).order_by('-pub_date')[:5] #""" #Return the last five published polls #(including those set to be published in the future). #""" #return Word.objects.order_by('-pub_date')[:5] def get_context_data(self, **kwargs): context = super(IndexView, self).get_context_data(**kwargs) # Filter 2 filter_2 = Word.objects.filter(direct_transl_word='') # Filter 4 filter_4 = Altword.objects.filter(rosword__direct_transl_word='') context.update({ "filter_2": filter_2, "filter_4": filter_4 }) return context #_______________________________________________________________________________ #_______________________________________________________________________________ class AltwordlistView(generic.DetailView): #model = Word model = Altword template_name = 'navi_polls/altword_list.html' context_object_name = 'poll' def get_queryset(self): #""" #Excludes any polls that aren't published yet. #""" #return Word.objects.filter(pub_date__lte=timezone.now()) # Filter 5 #return Word.objects.filter(direct_transl_word='') #return Word.objects.filter(direct_transl_word='').order_by('-votes') return Word.objects.filter(direct_transl_word='').order_by('-altword_rosword__votes') #return Altword.objects.filter(rosword__direct_transl_word='') #return Altword.objects.filter(word__direct_transl_word='') def get_context_data(self, **kwargs): context = super(AltwordlistView, self).get_context_data(**kwargs) # Filter 4b filter_4b = Altword.objects.filter(rosword__direct_transl_word='').order_by('-votes') # Filter 7 filter_7 = Altword.objects.vote_order() # Filter 8b # filter_8b = Altword.objects.filter(word__pk=word_id).order_by('-votes') context.update({ "filter_4b": filter_4b, "filter_7": filter_7 # "filter_8b": filter_8b }) return context # Filter 8 def altword_list(self, request, word_id): #object_list = AltWord.objects.filter(word__pk=word_id).order_by('-votes') object_list = Altword.objects.filter(word__pk=word_id).order_by('-votes') return render(request, 'navi_polls/altword_list.html', { 'poll_list': object_list, })
* altword_list.html
<h1>{{ poll.rosword }} - id:{{ poll.id }}</h1> <!-- Filter 8 --> {% if poll_list %} <ul> {% for row in poll_list %} <li>( id:{{ row.id }} ) - {{ row.rosword }}</li> {% endfor %} </ul> {% else %} <p>No list is available.</p> {% endif %} <h3>Filter 8</h3><!-- Filter 8 --> <table border="1"> <tr> <th>Altword_id</th> <th>Rosword</th> <th>Alt ros word</th> <th>Alt transl word</th> <th>Articulate</th> <th>Votes</th> </tr> <!-- poll.altword_set.all.order_by('-votes') --> <!-- for choice in poll.altword_set.all --> <!-- for choice in poll %} --> <!-- for choice in poll_list --> <!-- for choice in poll_list.altword_rosword.all --> {% for choice in poll_list %} <tr> <td>{{ choice.id }}</td> <td>{{ choice.rosword }}</td> <td>{{ choice.alt_ros_word }}</td> <td>{{ choice.alt_transl_word }}</td> <td>{{ choice.articulate }}</td> <td>{{ choice.votes }}</td> </tr> {% endfor %} </table> <h3>Filter 5</h3><!-- Filter 5 --> <table border="1"> <tr> <th>Altword_id</th> <th>Rosword</th> <th>Alt ros word</th> <th>Alt transl word</th> <th>Articulate</th> <th>Votes</th> </tr> <!-- poll.altword_set.all.order_by('-votes') --> <!-- for choice in poll.altword_set.all --> <!-- for choice in poll %} --> {% for choice in poll.altword_rosword.all %} <tr> <td>{{ choice.id }}</td> <td>{{ choice.rosword }}</td> <td>{{ choice.alt_ros_word }}</td> <td>{{ choice.alt_transl_word }}</td> <td>{{ choice.articulate }}</td> <td>{{ choice.votes }}</td> </tr> {% endfor %} </table> <h3>Filter 7</h3> <!-- Filter 7 --> <ul> {% for choice in filter_7 %} <li>{{ choice }} = {{ choice.votes }} votes</li> {% endfor %} </ul> <ul> {% for choice in filter_7 %} <li>{{ choice.rosword }} - {{ choice.alt_ros_word }} = {{ choice.votes }} votes</li> {% endfor %} </ul> <h3>Filter 4b</h3> <!-- Filter 4b --> <ul> {% for choice in filter_4b %} <li>{{ choice.rosword }} - {{ choice.alt_ros_word }} - {{ choice.alt_transl_word }} - {{ choice.articulate }} = {{ choice.votes }} votes</li> {% endfor %} </ul>
On Tue, Oct 15, 2013 at 8:30 AM, Leonardo Giordani <giordani.leonardo@gmail.com> wrote:
Cheers,Can you check the code you posted? The get_query() function is empty so this code, as posted, can not run.Please post even the urls you are using to call the view.
LeoLeonardo GiordaniAuthor of The Digital Cat
My profile on About.me - My GitHub page - My Coderwall profile
2013/10/15 Pepsodent Cola <pepsodentcola@gmail.com>--Hi,I got some help by somebody on #django IRC. They gave me this code snippet to fix my problem. But I'm having problems incorporating that code into my Class file because Template file says "No list is available" when I try to access the list variable. What am I doing wrong?# Filter 8def altword_list(self, request, word_id):#object_list = AltWord.objects.filter(word__pk=word_id).order_by('-votes')object_list = Altword.objects.filter(word__pk=word_id).order_by('-votes')return render(request, 'navi_polls/altword_list.html', {'poll_list': object_list,})
Views#_______________________________________________________________________________class AltwordlistView(generic.DetailView):#model = Wordmodel = Altwordtemplate_name = 'navi_polls/altword_list.html'context_object_name = 'poll'def get_queryset(self):# Filter 5#return Word.objects.filter(direct_transl_word='')def get_context_data(self, **kwargs):context = super(AltwordlistView, self).get_context_data(**kwargs)# Filter 4bfilter_4b = Altword.objects.filter(rosword__direct_transl_word='').order_by('-votes')# Filter 7filter_7 = Altword.objects.vote_order()# Filter 8b# filter_8b = Altword.objects.filter(word__pk=word_id).order_by('-votes')
context.update({"filter_4b": filter_4b,"filter_7": filter_7# "filter_8b": filter_8b})return context# Filter 8def altword_list(self, request, word_id):#object_list = AltWord.objects.filter(word__pk=word_id).order_by('-votes')object_list = Altword.objects.filter(word__pk=word_id).order_by('-votes')return render(request, 'navi_polls/altword_list.html', {'poll_list': object_list,})#_______________________________________________________________________________Template#_______________________________________________________________________________<!-- Filter 8 -->{% if poll_list %}<ul>{% for row in poll_list %}<li>( id:{{ row.id }} ) - {{ row.rosword }}</li>{% endfor %}</ul>{% else %}<p>No list is available.</p>{% endif %}<!-- poll.altword_set.all.order_by('-votes') --><!-- for choice in poll.altword_set.all --><!-- for choice in poll %} --><!-- for choice in poll_list --><!-- for choice in poll_list.altword_rosword.all -->{% for choice in poll_list %}
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+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/d8f21d91-e06d-428d-923d-08ace9d8df8a%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
--To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAEhE%2BOmK17x_ZVqcFxpOMBGqQ7qTzjhFPD233r94qyQU9i9kbg%40mail.gmail.com.
You received this message because you are subscribed to a topic in the Google Groups "Django users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/django-users/32WV-oD5rSc/unsubscribe.
To unsubscribe from this group and all its topics, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
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+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAOWMwCzrZZhzuHgFnY8NWsozZWv3UxarhTmAVE0xqvj6mVTuyQ%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.
No comments:
Post a Comment