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 trialSimon Amz
4,606 PointsHow to return zero records?
In the exercise, I have to return zero records if the term to look for is blank, but the bummer message is not clear enough I don't know where the error comes from.
Thanks for the clues.
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_queryset(self):
if self.kwargs["term"]:
return self.model.objects.filter(model.body__icontains=self.kwargs["term"])
else:
return
1 Answer
Quentin Vadon
2,263 PointsHi,
To return an empty queryset you can do MyModel.objects.none()
;-)