【发布时间】:2016-03-26 17:19:51
【问题描述】:
我的 models.py 如下所示:
class Exercise(models.Model):
#Field for storing exercise type
EXERCISE_TYPE_CHOICES = (
(1, 'Best stretch'),
(2, 'Butterfly reverse'),
(3, 'Squat row'),
(4, 'Plank'),
(5, 'Push up'),
(6, 'Side plank'),
(7, 'Squat'),
)
exercise_type = models.IntegerField(choices=EXERCISE_TYPE_CHOICES)
#Field for storing exercise name
-- Here comes the logic --
#Field for storing intensity level
INTENSITY_LEVEL_CHOICES = (
(1, 'Really simple'),
(2, 'Rather Simple'),
(3, 'Simple'),
(4, 'Okay'),
(5, 'Difficult'),
(6, 'Rather Difficult'),
(7, 'Really Difficult'),
)
intensity_level = models.IntegerField(choices=INTENSITY_LEVEL_CHOICES)
#Field for storing video url for a particular exercise
video_url = models.URLField()
#Field for storing description of the exercise
description = models.CharField(max_length=500)
我希望有一个名为“exercise_name”的字段用于课堂练习,但方式如下:
- 对于 exercise_type=1,它应该是“最佳拉伸”
- 对于 exercise_type=1,它应该是 'Butterfly reverse' 等等。
我怎样才能做到这一点?或者如果不是这样,有没有更好的方法来做到这一点?
底线:我的练习应该包含以下字段 - 类型、名称、描述、视频网址
【问题讨论】:
标签: python django django-models django-rest-framework