generated from Code-Institute-Org/gitpod-full-template
-
Notifications
You must be signed in to change notification settings - Fork 1
/
models.py
85 lines (67 loc) · 2.24 KB
/
models.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
from django.db import models
from django.contrib.auth.models import User
class Exercise(models.Model):
"""
Model representing an exercise.
Fields:
- name: CharField representing the name of the exercise.
Methods:
- __str__: Returns a string representation of the exercise object.
Usage Example:
exercise = Exercise.objects.get(id=1)
print(exercise)
"""
name = models.CharField(max_length=200, unique=True)
def __str__(self):
return self.name
class WorkoutItem(models.Model):
"""
Model representing a workout item.
Fields:
- exercise: ForeignKey field representing
the exercise associated with the workout item.
- reps: PositiveIntegerField representing
the number of repetitions for the workout item.
- sets: PositiveIntegerField representing
the number of sets for the workout item.
Methods:
- __str__: Returns a string representation of the workout item object.
Usage Example:
workout_item = WorkoutItem.objects.get(id=1)
print(workout_item)
"""
exercise = models.ForeignKey(
Exercise,
on_delete=models.CASCADE,
)
reps = models.PositiveIntegerField()
sets = models.PositiveIntegerField()
def __str__(self):
return f"{self.exercise}: sets - {self.sets} reps - {self.reps}"
class Workout(models.Model):
"""
Model representing a workout.
Fields:
- owner: ForeignKey field representing the owner (user) of the workout.
- name: CharField representing the name of the workout.
- instructions: TextField representing the instructions for the workout.
- exercises: ManyToManyField representing
the exercises associated with the workout.
Methods:
- __str__: Returns a string representation of the workout object.
Usage Example:
workout = Workout.objects.get(id=1)
print(workout)
"""
owner = models.ForeignKey(
User,
related_name="user_id",
on_delete=models.CASCADE,
)
name = models.CharField(max_length=250, unique=True)
instructions = models.TextField(max_length=1000, null=True, blank=True)
exercises = models.ManyToManyField(
WorkoutItem
)
def __str__(self):
return f"{self.owner}: {self.name}"