我有这个模型结构:
class Item(db.Model):
artist = db.StringField()
class Collection(db.Model):
# a collection delivers a list of items.
name = db.StringField()
class ListCollection(Collection):
# the items are static
items = db.ListField(Item)
class OtherCollection(Collection):
# the items are queried dynamically, like a dynamic playlist for example
artist = db.StringField()
@property
def items(self):
return Item.objects(artist=artist).all()
现在,OtherCollection
我认为搞砸了模型-> 视图分离。OtherCollection
有一个名字,可能是所有者等等(因此,我认为它是一个“模型”),但items
它是数据库查询的结果,至少在OtherCollection
子类中是这样。查询可以被认为是“视图”,而不是模型。
我的问题是:如何以不同的方式建模?