0

I am sorry if my query is stupid but please excuse me as i am new to google app engine and python I have and entity named Location

class Location(db.Model):
    place = db.StringProperty(required = True)
    address = db.TextProperty(required = True)
    approx_distance = db.StringProperty(required = True)

The GQL query

location = db.GqlQuery("SELECT * FROM Location WHERE place='Mumbai'")

gives an attribute error

 AttributeError: 'GqlQuery' object has no attribute 'place'

Please help

Bhushan
  • 354
  • 9
  • 25
  • 1
    In addition to the answer below, try using the model objects to perform queries. `location = Location.all().filter('place = ','Mumbai').get()` rather than using GQL. I have found 99% of the time I never use GQL. Oh and if you are just starting out with appengine I would strongly suggest you use `ndb` rather than `db`. – Tim Hoffman Jan 21 '14 at 13:44
  • The mistake that people often make is believing that GQL is somehow closer to the "native" datastore, in the same way that SQL is more native than an ORM in a traditional database. That's not the case: GQL is an artificial implementation on top of the query engine, just as the db/ndb libraries are. – Daniel Roseman Jan 21 '14 at 15:08

1 Answers1

3

You should look at the line of code that error is happening on; it's not the lines you post. You're probably doing something like location.place later on, but location is a GqlQuery, not the results of the query. You probably want:

location = db.GqlQuery("SELECT * FROM Location WHERE place='Mumbai'").get()

To get the first result, or use fetch to get a list of results.

Jesse Rusak
  • 56,530
  • 12
  • 101
  • 102