hy Мне нужно добавить свойство к модели, которое может ссылаться на 4 разные модели:
class WorldObject(db.Model):
# type can only accept: text, image, profile, position
# this should be like a set property in relational database and not a string
type = db.StringProperty(required = True)
# ???: this can be a reference to Profile, Image, Position or Text model
# how to do it?
reference = db.ReferenceProperty(reference_class = ???, required = True)
спасибо
@ Ник Джонсон:
ЗдесьВот как я поступил с вашей помощью:
class WorldObject(db.Model):
# x, y: position in the world
x = db.IntegerProperty(required = True)
y = db.IntegerProperty(required = True)
# world: reference to the world containing it
world = db.ReferenceProperty(reference_class = World)
# profile: is the owner of the object and is the only one who can make changes to it's world object property
owner = db.ReferenceProperty(reference_class = Profile, required = False)
# history
updated = db.DateTimeProperty(auto_now_add = True)
created = db.DateTimeProperty(required = True)
, затем:
class ImageWO(WorldObject):
image = db.ReferenceProperty(reference_class = Image, required = False)
, затем:
class PositionWO(WorldObject):
position = db.ReferenceProperty(reference_class = Position, required = False)
и другие классы такие же ..Теперь, если я хочу собрать все объекты мира в области, как мне это сделать?Я должен сделать 1 запрос для каждого класса, который расширяет world_object?