Hi Gilles -

if you've imported "models", you need to refer to Series as "models.Series", 
unless you imported Series individually which seems to not be the case.

The second part of things, if you call query.filter(), you get a new Query 
object back, just like with most Query methods, until you do one of the 
following:   iterate it, e.g. "for  x in query:", or call one of .all(), 
.one(), or .first().



On Aug 30, 2014, at 11:12 AM, Gilles Coulais <gilles.coul...@gmail.com> wrote:

> Hi all,
> 
> I'm starting to have a look at sqlalchemy and Flask and have a problem I 
> can't figure out. I have a set of models and am trying to play with the 
> corresponding database in a python console. Here is my models file: 
> http://snipurl.com/297pxcw
> 
> The following query will execute as expected and return a list of Series 
> objects, as present in the database
> from book_catalog import models, db
> series = models.Series.query.all()
> for serie in series:
>     print serie.id, serie.name
> 1 Nikopol
> 
> But executing the following query will return an error:
> nikopol = models.Series.query.filter(Series.name == 'Nikopol')
> Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
> NameError: name 'Series' is not defined
> 
> I tried the following, which is executing, but returning a Query object (not 
> exactly what I'm trying to do ;) )
> nikopol = models.Series.query.filter(models.Series.name == 'Nikopol')
> print nikopol
> SELECT series.id AS series_id, series.name AS series_name 
> FROM series 
> WHERE series.name = :name_1
> 
> Can anyone explain what I'm doing wrong here? I'm using SqlAlchemy 0.9.7
> 
> sqlalchemy.__version__
> '0.9.7'
> 
> Thanks a lot in advance.
> 
> Gilles
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "sqlalchemy" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to sqlalchemy+unsubscr...@googlegroups.com.
> To post to this group, send email to sqlalchemy@googlegroups.com.
> Visit this group at http://groups.google.com/group/sqlalchemy.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to