我有一个项目模型如下:
class Project(me.Document):
title = me.StringField(max_length=64, required=True, unique=True)
start_date = me.DateTimeField(default=datetime.utcnow())
end_date = me.DateTimeField(default=datetime.utcnow())
duration = me.IntField() # sprint duration
sequence = me.IntField()
def __init__(self, *args, **values):
super(Project, self).__init__( *args, **values)
def __str__(self):
return self.title
def get_current_sprint(self):
''' A logic here to calculate the current sprint.'''
还有另一个模型冲刺:
class Sprint(me.Document):
start_date = me.DateTimeField()
end_date = me.DateTimeField()
sequence = me.IntField(required=True, default=0, unique_with='project')
project = me.ReferenceField('Project')
如果我有project
实例,那么我可以通过调用该方法来获得当前的 sprint
project.get_current_sprint()
但我想要的是;每当查询项目对象时,而不是调用方法来获取当前 sprint,它应该有一个project.current_sprint
具有当前 sprint 信息的属性。
有没有办法实现它?
任何帮助将非常感激。