I am having trouble understanding what the Debug wants me to fix and how to 
fix it?
Isn't my models already defined?  Isn't my queryset already defined in 
variables filter_1, 2 and 3?

Exception Type: ImproperlyConfigured  Exception Value: 

*'IndexView' must define 'queryset' or 'model'*

 Exception Location: 
/usr/local/lib/python2.7/dist-packages/django/views/generic/list.py 
in get_queryset, line 35


*views.py*

from polls.models import Word, Pronunciation
#_______________________________________________________________________________

class IndexView(generic.ListView):
    template_name = 'polls/index.html'
    #context_object_name = 'latest_poll_list'

#  def get_queryset(self):
    def get_context_data(**kwargs):
        context = super(IndexView, self).get_context_data(**kwargs)

# Filter 1
        filter_1 = Word.objects.filter(pub_date__lte=timezone.now()
                  ).order_by('-pub_date')[:5]
# Filter 2
        filter_2 = Word.objects.filter(translation='')
# Filter 3
        filter_3 = Pronunciation.objects.filter(wordfield__translation='')

        context.update({
            "filter_1": filter_1,
            "filter_2": filter_2,
            "filter_3": filter_3
        })
        return context
#_______________________________________________________________________________






On Tuesday, July 23, 2013 8:17:36 AM UTC+2, Tundebabzy wrote:
>
> Override your get method but it's easier to override the get_context_data 
> method like
> # From my head 
> def get_context_data(**kwargs):
>     context = super(IndexView, self).get_context_data(**kwargs)
>     #filter1 is already present as latest_poll_list in the context
>     filter2 = Word.blah()
>     filter3 = Word.blah_blah()
>     context.update({
>         "filter2": filter2,
>         "filter3": filter3
>     })
>     return context
>
> Sent from my Windows Phone
> ------------------------------
> From: Pepsodent Cola
> Sent: 7/22/2013 9:47 PM
> To: django...@googlegroups.com <javascript:>
> Subject: Re: Can I only have one "get_queryset" per Viewpage?
>
> I'm having difficulty understanding the abstract explanations in that 
> documentation.
> Could you or somebody else explain this, by showing by example using my 
> code examples?
>
> *views.py*
>
> class IndexView(generic.ListView):
>     template_name = 'polls/index.html'
>     context_object_name = *'latest_poll_list'*
>
>     def get_queryset(self):
>         """
>         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]
>
> *### Filter 2*
> #Word.objects.filter(translation='')
> *### Filter 3*
> #Pronunciation.objects.filter(wordfield__translation='')
>
>
>
>
> *index.html*
>
> <h1>index.html</h1>
>
> {% if latest_poll_list %}
>     <ul>
>     {% for word in *latest_poll_list* %}
>         <li><a href="{% url 'polls:detail' word.id %}">{{ word.wordfield 
> }}</a></li>
>     {% endfor %}
>     </ul>
> {% else %}
>     <p>No polls are available.</p>
> {% endif %}
>
>
>
> How should I write my IndexView class so that Filter 1, 2 and 3 list 
> results are then sent to my index.html template file?
>
>
>
>
> On Monday, July 22, 2013 2:03:59 PM UTC+2, macndesign wrote:
>>
>> Hi, you can separate your querysets in get_context_data method.
>> See: 
>> https://docs.djangoproject.com/en/dev/ref/class-based-views/mixins-simple/#django.views.generic.base.ContextMixin.get_context_data
>>
>>
>> 2013/7/22 Pepsodent Cola <pepsod...@gmail.com>
>>
>>> Hi,
>>>
>>> Can I only have one "get_queryset" for each Viewpage?
>>> If I wanted to add another database list on the same Viewpage how would 
>>> that code look like for my Django *views.py* file?
>>>
>>> Example:
>>> https://docs.djangoproject.com/en/1.5/intro/tutorial04/#amend-views
>>>
>>> from polls.models import Choice, Poll
>>>
>>> class IndexView(generic.ListView):
>>>     template_name = 'polls/index.html'
>>> *    context_object_name = 'latest_poll_list'*
>>>
>>> *    def get_queryset(self):*
>>>         """Return the last five published polls."""
>>>         return Poll.objects.order_by('-pub_date')[:5]
>>>
>>>
>>>
>>> I mean will "context_object_name" be able to separate between several 
>>> "get_queryset(self)"?
>>> Because I want to have several different poll_lists on the same Viewpage.
>>>
>>> context_object_name = 'latest_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...@googlegroups.com.
>>> To post to this group, send email to django...@googlegroups.com.
>>> Visit this group at http://groups.google.com/group/django-users.
>>> For more options, visit https://groups.google.com/groups/opt_out.
>>>  
>>>  
>>>
>>
>>
>>
>> -- 
>> Att. *Mário Araújo Chaves Neto*
>> *Programmer, Designer and U.I. Engineer*
>> *
>> *
>> *MBA in Design Digital* - 2008 - FIC
>> *Analysis and Systems Development* - 2011 - Estácio
>> *D**esign and Implementation of Internet Environments* - 2003 - FIC
>>  
>  -- 
> 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 <javascript:>.
> To post to this group, send email to django...@googlegroups.com<javascript:>
> .
> Visit this group at http://groups.google.com/group/django-users.
> For more options, visit https://groups.google.com/groups/opt_out.
>  
>  
>

-- 
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+unsubscr...@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.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to