Lets say we have following models.
class User(db.Model):
username=db.StringProperty()
avatar=db.ReferenceProperty()
class User(db.Model):
username=db.StringProperty()
avatar=db.StringProperty()
class Avatar(db.Model):
avatarLink=db.StringProperty
class UserDataHandler:
def adduserdata():
userid="uniqueid1"
avatarid="uniqueid2"
user=User(key_name=userid)
avatar=Avatar(key_name=user)
avatar.avatar="http://zy.jpg"
avatar.put()
user.username="username"
user.avatar=avatar
#user.avatar=avatarid
Of the above two models of is it better to use ReferenceProperty model or store key_name of the avatar instead and get Avatar from key. By better I mean which one uses the least number of database queries.
Both methods will result in the same number of queries; using a ReferenceProperty is just less code you have to write (and thus generally considered the right way to do it).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With