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
38 lines (30 loc) · 1.29 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
# 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.
class CarMake(models.Model):
name = models.CharField(max_length=100, unique=True)
description = models.TextField(blank=True)
country_of_origin = models.CharField(max_length=50, blank=True)
established_year = models.PositiveIntegerField(null=True, blank=True)
def __str__(self):
return self.name
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'),
]
type = models.CharField(max_length=10, choices=CAR_TYPES, default='SUV')
year = models.IntegerField(default=2023,
validators=[
MaxValueValidator(2023),
MinValueValidator(2015)
])
# Additional optional field: engine size (for example)
engine_size = models.CharField(max_length=50, blank=True, help_text="Engine size description")
def __str__(self):
return self.name # Return the name as the string representation