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 trial

Python Django Class-based Views Customizing Class-based Views Override get_queryset

Anton Kamynin
Anton Kamynin
20,412 Points

CBV code challenge problem

Have no idea what else I should do in this challenge

articles/views.py
from django.views import generic

from . import models


class ArticleList(generic.ListView):
    model = models.Article


class ArticleDetail(generic.DetailView):
    model = models.Article


class ArticleCreate(generic.CreateView):
    fields = ('title', 'body', 'author', 'published')
    model = models.Article


class ArticleUpdate(generic.UpdateView):
    fields = ('title', 'body', 'author', 'published')
    model = models.Article


class ArticleDelete(generic.DeleteView):
    model = models.Article


class ArticleSearch(generic.ListView):
    model = models.Article

    def get_queryest(self):
        if self.kwargs["term"]:
            return self.model.objects.filter(body__icontains=self.kwargs["term"])
        else:
            return self.model.objects.none()

1 Answer

Ryan S
Ryan S
27,276 Points

Hi Anton,

Your code is basically correct except for a small typo in the name of your method. You mixed the "s" and "e" around in "get_queryset".