Using the following models I am trying to figure out a way to generate a news feed of sorts so that when a user logs in they are presented with a list of upcoming events for bars that they choose to follow. Will I be able to query something like “SELECT * FROM Barevent WHERE parent_bar IN UserprofileInstance.following”? If so will this be efficient?
class Barprofile(db.Model):
b_user = db.UserProperty()
created = db.DateTimeProperty(auto_now_add=True)
barname = db.StringProperty()
address = db.PostalAddressProperty()
zipcode = db.StringProperty()
class Barevent(db.Model):
created = db.DateTimeProperty(auto_now_add=True)
when = db.DateProperty()
starttime = db.TimeProperty()
endtime = db.TimeProperty()
description = db.StringProperty(multiline=True)
parent_bar = db.ReferenceProperty(Barprofile, collection_name='bar_events')
class Userprofile(db.Model):
b_user = db.UserProperty()
following = db.ListProperty(db.Key)
Your model and your query should work fine, and it would not be inefficient. The one thing that you will want to keep in mind is that if Barprofile entities are deleted, you may want to manually remove their keys from the following property of each Userprofile. Having an orphaned Barprofile reference will not break the query, but if you ever use that list for other purposes (such as displaying to a user which bars he or she is subscribed to), you will got an error if you try to query on that key.