Reputation: 37137
Hey I have this code but it doesn't work because it is expecting a string. How can I make it work?
class Atable(BaseModel):
owner = db.UserProperty()
(...)
--------- // --------------
query = "SELECT * FROM Atable WHERE owner=", users.get_current_user()
results = db.GqlQuery(query)
How can I fix that search? Thanks :)
I've started with the appengine database yesterday so be gentle :)
Upvotes: 1
Views: 766
Reputation: 14213
query = GqlQuery("SELECT * FROM Atable WHERE owner = :1", users.get_current_user())
Upvotes: 2
Reputation: 5352
The python query way is probably easier if you just need to get some data for that user.
For example in your class Something(db.Model), you can define:
@staticmethod
def get_something_by_user(user):
query = db.Query(Something).filter('users =', user)
result = query.fetch(limit=1000)
return result
Then you call it by doing this:
user = users.GetCurrentUser()
results = Something.get_something_by_user(user)
Upvotes: 0
Reputation: 46264
You could try the GQL way:
results = db.GqlQuery("SELECT * FROM Atable WHERE owner = :1", users.get_current_user().key())
or the Python Query way:
query = db.Query(Atable)
results = query.filter('owner =', users.get_current_user())
Upvotes: 3