我正在使用django制作锻炼日记网站,我使用MongoDB获得以下模型:
from mongoengine import *
class Person(Document):
name = StringField(max_length = 200)
person_id = IntField(unique = True)
def __str__(self):
return str(self.person_id) + self.name
class Lift(EmbeddedDocument):
lift_id = IntField(unique=True)
name = StringField(max_length=200) #e.g. bench press, etc
sets = ListField(IntField()) # No of reps in each set
def __str__(self):
return self.name
class Cardio(EmbeddedDocument):
cardio_id = IntField(unique=True)
name = StringField(max_length=200)
duration = IntField() #Number of minutes
distance = IntField() #Number of metres
def __str__(self):
return self.name
class Workout(Document):
id = IntField(unique=True, null=False)
date = DateTimeField()
person = ReferenceField(Person)
lifts = ListField(EmbeddedDocumentField(Lift))
cardio = ListField(EmbeddedDocumentField(Cardio))
def __str__(self):
return str(self.date)+" "+self.person.name
由于Workout的EmbeddedDocumentField
和lifts
cardio
中ListField
的数量理论上可以是无限的,我需要允许用户指定多少lifts
{1}}(对应于"设置"在健身房中)和/或他们想要添加到锻炼中的cardio
活动。因此,我的表单需要基于初始用户输入具有动态数量的输入。我的问题是,Django是否覆盖了这种方式,还是需要使用Javascript?