generated from ibm-developer-skills-network/coding-project-template
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
/
Copy pathmodels.py
50 lines (43 loc) · 1.73 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
# Uncomment the following imports before adding the Model code
from django.db import models
from django.utils.timezone import now
from django.core.validators import MaxValueValidator, MinValueValidator
# Create your models here.
# <HINT> Create a Car Make model `class CarMake(models.Model)`:
# - Name
# - Description
# - Any other fields you would like to include in car make model
# - __str__ method to print a car make object
class CarMake(models.Model):
name = models.CharField(max_length = 100)
description = models.TextField()
year = models.PositiveIntegerField(default=2024)
def __str__(self):
return self.name
# <HINT> Create a Car Model model `class CarModel(models.Model):`:
# - Many-To-One relationship to Car Make model (One Car Make has many
# Car Models, using ForeignKey field)
# - Name
# - Type (CharField with a choices argument to provide limited choices
# such as Sedan, SUV, WAGON, etc.)
# - Year (IntegerField) with min value 2015 and max value 2023
# - Any other fields you would like to include in car model
# - __str__ method to print a car make object
class CarModel(models.Model):
car_make = models.ForeignKey(CarMake, on_delete=models.CASCADE) # Many-to-One relationship
name = models.CharField(max_length=100)
CAR_TYPES = [
('SEDAN', 'Sedan'),
('SUV', 'SUV'),
('WAGON', 'Wagon'),
# Add more choices as required
]
type = models.CharField(max_length=10, choices=CAR_TYPES, default='SUV')
year = models.IntegerField(default=2023,
validators=[
MaxValueValidator(2023),
MinValueValidator(2015)
])
# Other fields as needed
def __str__(self):
return self.name # Return the name as the string representation