Hi, I am trying to create an application that has models similar to some of them :-( Although it would be easy to combine the two models into one and use them, but this is not possible in a real application)class User(db.Model):
username=db.StringProperty()
email=db.StringProperty()
class UserLikes(db.Model):
username=db.StringProperty()
food=db.StringProperty()
Purpose. After logging in, the user enters the food he likes and the application, in turn, returns all other users who like this food. Now suppose user Alice says she likes Pizza, she is stored in a data warehouse. She logs out and logs back in. At this point, we request a data warehouse for food that she likes, and then again request all users who love this food. These, as you can see, are two data warehouse queries, which is not the best way. I am sure there will definitely be a better way to do this. Maybe someone can help.
[Update: -Or you can do something similar to change the second model so that user names become a multi-valued property that can store all users who love this food. However, I'm a little obscure here]
[Edit: -Hi Thanks for the answer, but I found both solutions below a bit of an excess. I tried to do this as shown below. Try a look at this and kind advice. I supported the same two tables, but changed them as shown below: -
class User(db.Model):
username=db.StringProperty()
email=db.StringProperty()
class UserLikes(db.Model):
username=db.ListProperty(basestring)
food=db.StringProperty()
Now, when 2 users update the same food that they like, it is saved as
'pizza' ----> 'Alice', 'Bob'
And my db query to retrieve the data becomes quite simple here.
query=db.Query(UserLikes).filter('username =','Alice').get()
which can then be sorted out as something like
for elem in query.username:
print elem
Now, if there are two products, as shown below: -
'pizza' ----> 'Alice','Bob'
'bacon'----->'Alice','Fred'
, , , .
, , . !