연습용 추적 응용 프로그램을 만들고 모델을 만드는 가장 효율적인 방법에 대해 궁금합니다. 대부분의 운동에는 반복, 세트 및 체중이 있습니다. 그러나 거리와 시간이있는 달리기가 있습니다. 처음에는 각각을 포착 할 수있는 두 가지 모델을 만들려고했으나 그 때 결합하는 것이 더 나을 것이라고 생각했습니다. 자, 나는 잘 모르겠다. 조깅은 운동의 일종이며 다른 측정 특성을 가지고 있기 때문에 단지 밖으로 분리하기 때문에Django 모델의 올바른 구성
LEVELS = (
(1, '1 - Hardly'),
(2, '2'),
(3, '3'),
(4, '4'),
(5, '5 - Average'),
(6, '6'),
(7, '7'),
(8, '8'),
(9, '9'),
(10, '10 - Very'),
class Jog(models.Model):
distance = models.DecimalField("Distance (Miles)", max_digits=4, decimal_places=2)
time = models.DecimalField("Time (Minutes)", max_digits=4, decimal_places=2)
intensity = models.IntegerField("Intensity", choices = LEVELS, default = 5)
date = models.DateTimeField("Date", blank=True, default=datetime.now)
notes = models.TextField("Notes", blank=True)
def __str__(self):
return "%s Miles in %s Minutes (Intensity of %s)" % (self.distance, self.time, self.intensity)
class Meta:
verbose_name = "Jog"
class Exercise_Type(models.Model):
name = models.CharField("Exercise Name", max_length=200, unique = True)
slug = models.SlugField(max_length=100, blank=True)
notes = models.TextField("Notes", blank=True)
def __str__(self):
return self.name
class Workout(models.Model):
exercise_type = models.ForeignKey(Exercise_Type, verbose_name="Exercise Type")
reps = models.IntegerField("Repetitions")
sets = models.DecimalField("Sets", max_digits=2, decimal_places=1)
weight = models.IntegerField("Weight", blank=True, null=True)
intensity = models.IntegerField("Intensity", choices = LEVELS, default = 5)
date = models.DateTimeField("Date", blank=True, default=datetime.now)
notes = models.TextField("Notes", blank=True)
이 비록 바보 같았다 :
확인은 아래에있는 내 첫 번째 패스이다. 그래서 나는 이렇게 생각했습니다. 만약 내가 이렇게하면. 운동 유형에 필요한 필드를 정의하고 사용자에게 운동의 유형을 요청하여이를 억제/사용 :
class Exercise_Type(models.Model):
name = models.CharField("Exercise Name", max_length=200, unique = True)
slug = models.SlugField(max_length=100, blank=True)
notes = models.TextField("Notes", blank=True)
distance = models.BooleanField("Use Distance Field?", default = False)
time = models.BooleanField("Use Time Field?", default = False)
reps = models.BooleanField("Use Reps Field", default = False)
sets = models.BooleanField("Use Sets Field?", default = False)
weight = models.BooleanField("Use Weight Field?", default = False)
def __str__(self):
return self.name
class Workout(models.Model):
exercise_type = models.ForeignKey(Exercise_Type, verbose_name="Exercise Type")
distance = models.DecimalField("Distance (Miles)", max_digits=4, decimal_places=2, blank = True, null=True)
time = models.DecimalField("Time (Minutes)", max_digits=4, decimal_places=2, blank = True, null=True)
reps = models.IntegerField("Repetitions", blank = True, null=True)
sets = models.DecimalField("Sets", max_digits=2, decimal_places=1, blank = True, null=True)
weight = models.IntegerField("Weight", blank=True, null=True)
intensity = models.IntegerField("Intensity", choices = LEVELS, default = 5)
date = models.DateTimeField("Date", blank=True, default=datetime.now)
notes = models.TextField("Notes", blank=True)
모든 운동에 관계없이 정보를 요구하는지의 모든 필드가 기술적으로하기 때문에 이것은 자원의 낭비처럼 보인다 아닙니다.
그런 다음 하위 분류는 어떻게됩니까? 그 때 나는 포기하고 자신보다 지식이 많은 사람들에게 호소하기로 결정했습니다.
이 모델을 구성하는 가장 좋은 방법은 무엇입니까?
+1, 운동 대신 운동의 일부가 아니어야합니다. 측정 값은 –
입니다. 운동 (또는 운동 연대)이 여러 날짜로 나뉘며 각 날짜마다 특정 운동을 수행 할 수 있습니다 . –
하지만 일반적으로 매일 운동, 별도의 하루 운동은 별도로 나열되어야합니다, 그렇지 않으면 하나의 운동 행 –