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 SQLAlchemy Basics Working with SQLAlchemy Analyzing the Movie Database

Andy McDonald
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Andy McDonald
Python Development Techdegree Graduate 13,801 Points

How to use like() method?

The quiz is expecting me to know how to use this when this is the first time I've ever seen anything like it. I can't google search for anything that is helping with this particular method. A hint on how to use this to get passed the quiz would be helpful

models.py
from sqlalchemy import create_engine, Column, Integer, String
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker


engine = create_engine(β€˜sqlite:///movies.db’, echo=False)
Session = sessionmaker(bind=engine)
session = Session()
Base = declarative_base()


class Movie(Base):
    __tablename__ = β€˜movies’

    id = Column(Integer, primary_key=True)
    movie_title = Column(String)
    genre = Column(String)

def the_movies():
    return session.query(Movie).filter(Movie.movie_title.like('%The%').count()
Andy McDonald
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Andy McDonald
Python Development Techdegree Graduate 13,801 Points

I did use it as a string and would never have known that it behaved completely differently with a query object had you not hinted to use it without any argument. I originally was just guessing what the quiz wanted but when I went back to look at my meticulous notes I started trying to pass arguments into it.

1 Answer

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,441 Points

Hey Andy McDonald, had to look a bit too! You are very close.

  • The like() is defined in the docs here

  • usage examples can be found in the docs on this page

The challenge asks to create a variable named the_movies. You've defined a function. So use, the_movies = ...

  • there is a syntax error where you are missing a closing paren before .count()

Post back if you need more help. Good luck!!

Chris Freeman
Chris Freeman
Treehouse Moderator 68,441 Points

Can you show the code that caused the request for an argument?

Many objects may have their own method named count(). The query set count() does not take an argument. list.count() takes exactly one argument, str.count() takes one or more. Perhaps the object requiring arguments wasn’t a query set.