python - How to add custom field to mongoengine model? -
i have project model follows:
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): ''' logic here calculate current sprint.''' and anther model 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') if have project instance can current sprint calling method
project.get_current_sprint() but trying ; whenever project object being queried, rather calling method current sprint, should have attribute project.current_sprint has current sprint info.
is there way achieve it?
any appreciated.
i think concept of you're looking called database references in mongodb.
in mongoengine, create referencefield in project model, reference sprint document.
Comments
Post a Comment