Google app engine gql requests two properties with the same string

I have a data model called Game.

In the model Game, I have two properties called player1and player2, which are their names.

I want to find a player in Game, but I do not know how to build a query, because gql does not support the sentence OR, and then I can not use the instruction select * from Game where player1 = 'tom' or player2 = 'tom'.

So how can I solve this issue?
Do I need to modify my data model?

+3
source share
3 answers

2 , player1 player2, Python.

, , ListProperty, :

class Game(db.Model):
  players = db.ListProperty()

game1.players = ['tom', 'bob']
game2.players = ['joe', 'tom']

# this query will match all games where tom is one of the players
query = Game.all().filter('players =', 'tom')

, .

+6

, , Python , .

name = "The Player"
keys1 = set(Game.all(keys_only=True).filter("player1 =", name))
keys2 = set(Game.all(keys_only=True).filter("player2 =", name))
games = Game.get( list(keys1 | keys2) )

3 / RPC, , , . , , ,

games1 = Game.all().filter("player1 =", name)
games2 = Game.all().filter("player2 =", name)
games = games1+filter(lambda x:x not in games1,games2)
+1

Note that when using the Drew scheme, there is no performance gain, because queries in the list properties must check equality with respect to all elements of the list.

0
source

All Articles