Thanks Tom that got rid of the Debug message.
My views.py code and index.html code now looks like this. But how exactly
do I send my IndexView query results (filter1, 2 and 3) to my index.html
template file?
The only thing I see on the webpage is this result:
<p>No polls are available.</p>
*views.py*
from polls.models import Word, Pronunciation, Altword
#_______________________________________________________________________________
class IndexView(generic.ListView):
template_name = 'polls/index.html'
context_object_name = 'context'
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
#_______________________________________________________________________________
*index.html*
<article>
<h1>index.html</h1>
{% if context %}
<ul>
{% for word in context %}
<li><a href="{% url 'polls:detail' word.id %}">{{ word.wordfield
}}</a></li>
{% endfor %}
</ul>
{% else %}
<p>No polls are available.</p>
{% endif %}
</article>
On Friday, July 26, 2013 11:29:54 AM UTC+2, Tom Evans wrote:
>
> On Fri, Jul 26, 2013 at 9:57 AM, Pepsodent Cola
> <[email protected]<javascript:>>
> wrote:
> >
> > 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'
>
> You must provide get_queryset() method, this will be represented in
> the template context by whatever name you set in context_object_name.
> If you want extra objects in the template context, you can add them by
> overriding get_context_data(), but you must still provide the
> get_queryset() method, it is not optional.
>
> Cheers
>
> Tom
>
--
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 [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.