Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Django ORM Basic ORM Usage Delete

Daniel Still
Daniel Still
10,532 Points

Django Challenge Task - Deleting Reviews

Here's the question...

"We're starting to get a lot of advertisement spam in our reviews. We're going to implement a better solution later, but for now, write a function named 'can_spam' that selects all of the 'Review(s)' where the comment field contains the string "http" and then delete them."

Here's my answer...

"from . import models

def can_spam(): http = Review.objects.filter(comment__icontains="http") http.delete()"

I cannot figure out what I did wrong. Any help would be massively appreciated. :)

products/utils.py
from . import models

def can_spam():
    http = Review.objects.filter(comment__icontains="http")
    http.delete()

2 Answers

Ryan S
Ryan S
27,276 Points

Hi Daniel,

Your code is basically correct. You just made a small error regarding the models import. Since you are importing the entire module, the model is accessed by using models.Review, rather than just Review.

from . import models

def can_spam():
    http = models.Review.objects.filter(comment__icontains="http")
    http.delete()