我有一个带有一些锻炼模型的卡片模型,每次锻炼都有完全相同的数据:锻炼名称、重复次数..等锻炼是 7 次,一周中的每一天。所以我用完全相同的数据编写了 7 个模型,这样在管理模型中我有 7 个锻炼,我可以为每个锻炼添加“+”我想要多少锻炼(使用内联)
有没有办法只编写一次锻炼模型,然后可以在管理界面中多次添加它?(每次我添加锻炼时,我都希望能够在同一个管理视图中添加锻炼名称、重复次数等)
class Card(models.Model):
number = models.IntegerField()
name = models.CharField(max_length=50)
surname = models.CharField(max_length=50)
trainer = models.CharField(max_length=50, blank=True, null=True)
#Card status
creation = models.DateField(auto_now_add=True)
expiration = models.DateField(blank=True, null=True)
#Member status
subscription = models.DateField(blank=True, null=True)
def __str__(self):
return u'%s %s' % (self.surname, self.name)
class Meta:
unique_together = (("number"),)
class Exercise(models.Model):
name = models.CharField(max_length=50)
def __str__(self):
return u'%s' % (self.name)
class Series(models.Model):
number = models.IntegerField()
def __str__(self):
return u'%s' % (self.number)
class Meta:
verbose_name = 'Series'
verbose_name_plural = 'Series'
class Repetitions(models.Model):
number = models.IntegerField()
def __str__(self):
return u'%s' % (self.number)
class Meta:
verbose_name = 'Repetition'
verbose_name_plural = 'Repetitions'
class Executions(models.Model):
mode = models.CharField(max_length=50)
def __str__(self):
return u'%s' % (self.mode)
class Meta:
verbose_name = 'Execution'
verbose_name_plural = 'Executions'
class Rest(models.Model):
time = models.IntegerField()
def __str__(self):
return u'%s' % (self.time)
class Meta:
verbose_name = 'Rest'
verbose_name_plural = 'Rest'
class Exercise1(models.Model):
card = models.ForeignKey(Card)
exercise = models.ForeignKey(Exercise)
series = models.ForeignKey(Series)
repetitions = models.ForeignKey(Repetitions)
executions = models.ForeignKey(Executions)
rest = models.ForeignKey(Rest)
class Meta:
verbose_name = 'Exercise'
verbose_name_plural = 'Workout 1'
def __str__(self):
return u'%s' % (self.exercise)
class Exercise2(models.Model):
card = models.ForeignKey(Card)
exercise = models.ForeignKey(Exercise)
series = models.ForeignKey(Series)
repetitions = models.ForeignKey(Repetitions)
executions = models.ForeignKey(Executions)
rest = models.ForeignKey(Rest)
class Meta:
verbose_name = 'Exercise'
verbose_name_plural = 'Workout 2'
def __str__(self):
return u'%s' % (self.exercise)
class Exercise3(models.Model):
card = models.ForeignKey(Card)
exercise = models.ForeignKey(Exercise)
series = models.ForeignKey(Series)
repetitions = models.ForeignKey(Repetitions)
executions = models.ForeignKey(Executions)
rest = models.ForeignKey(Rest)
class Meta:
verbose_name = 'Exercise'
verbose_name_plural = 'Workout 3'
def __str__(self):
return u'%s' % (self.exercise)
class Exercise4(models.Model):
card = models.ForeignKey(Card)
exercise = models.ForeignKey(Exercise)
series = models.ForeignKey(Series)
repetitions = models.ForeignKey(Repetitions)
executions = models.ForeignKey(Executions)
rest = models.ForeignKey(Rest)
class Meta:
verbose_name = 'Exercise'
verbose_name_plural = 'Workout 4'
def __str__(self):
return u'%s' % (self.exercise)
class Exercise5(models.Model):
card = models.ForeignKey(Card)
exercise = models.ForeignKey(Exercise)
series = models.ForeignKey(Series)
repetitions = models.ForeignKey(Repetitions)
executions = models.ForeignKey(Executions)
rest = models.ForeignKey(Rest)
class Meta:
verbose_name = 'Exercise'
verbose_name_plural = 'Workout 5'
def __str__(self):
return u'%s' % (self.exercise)