Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialThiago Oliveria
137 PointsThe queryset() method needs to call filter() on its 'queryset' argument.
i believe my code is right , i can't understand the message of the error:
"The queryset() method needs to call filter() on its 'queryset' argument." because , i use queryset argument in method with filter , but keep show the error i look in documentation the django and looks like right ...
Can someone show me when is my error ? or this is a bug ?
from django.contrib import admin
from . import models
class TextInline(admin.StackedInline):
model = models.Text
class QuizInline(admin.StackedInline):
model = models.Quiz
class AnswerInline(admin.StackedInline):
model = models.Answer
class TopicListFilter(admin.SimpleListFilter):
title = 'topic'
parameter_name = 'topic'
def lookups(self, request, admin_model):
return (
('Python', 'Python'),
('Ruby', 'Ruby'),
('Java', 'Java'),
)
def queryset(self, request, queryset):
if self.value() == 'Python':
return self.queryset.filter(title__contains='Python')
if self.value() == 'Ruby':
return self.queryset.filter(title__contains='Ruby')
if self.value() == 'Java':
return self.queryset.filter(title__contains='Java')
class CourseAdmin(admin.ModelAdmin):
inlines = [TextInline, QuizInline]
list_filter = ['created_at', 'is_live']
admin.site.register(models.Course, CourseAdmin)
1 Answer
Chris Freeman
Treehouse Moderator 68,457 PointsThe error is not in the code specifically. The challenge is looking for lowercase words. Also, the self.
prefix should not be used in this case since queryset
is not an attribute of the class, but rather an argument to the method.
def queryset(self, request, queryset):
if self.value() == 'python':
return queryset.filter(title__contains='python')
if self.value() == 'ruby':
return queryset.filter(title__contains='ruby')
if self.value() == 'java':
return queryset.filter(title__contains='java')