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 trialEdgar Castelo
Courses Plus Student 19,428 PointsWhat am I doing wrong? Django ORM - Filter
I assume everything is correct with my code but I keep getting an error. I just can't see what is missing.
from django.shortcuts import render
from . import models
def good_reviews(request):
reviews = Review.objects.filter(rating__gte=3)
return render(request, 'products/reviews.html', {'reviews':reviews })
1 Answer
Brendan Whiting
Front End Web Development Techdegree Graduate 84,738 PointsIt needs to be models.Review.objects.filter(rating__gte=3)
instead of starting with Review.
If you had said from models import *
then you could just start with Review, because it would have imported all the bits of models
, but the way it is now ,it doesn't know all those bits exist, it just knows models exists.
Edgar Castelo
Courses Plus Student 19,428 PointsEdgar Castelo
Courses Plus Student 19,428 PointsThank you Brendan.
Brendan Whiting
Front End Web Development Techdegree Graduate 84,738 PointsBrendan Whiting
Front End Web Development Techdegree Graduate 84,738 Pointssorry, I should clarify - the other way of importing would be
from . import models.Review
in this case, not what I said before.