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 ORM Basic ORM Usage Filter

Edgar Castelo
PLUS
Edgar Castelo
Courses Plus Student 19,428 Points

What 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.

products/views.py
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
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Brendan Whiting
Front End Web Development Techdegree Graduate 84,738 Points

It 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.