1- # Uncomment the following imports before adding the Model code
2-
31from django .db import models
4- from django .utils .timezone import now
52from django .core .validators import MaxValueValidator , MinValueValidator
63
74
85# Create your models here.
96
10- # <HINT> Create a Car Make model `class CarMake(models.Model)`:
11- # - Name
12- # - Description
13- # - Any other fields you would like to include in car make model
14- # - __str__ method to print a car make object
7+ # Car Make model
158class CarMake (models .Model ):
169 name = models .CharField (max_length = 100 )
1710 description = models .TextField ()
@@ -21,32 +14,35 @@ def __str__(self):
2114 return self .name
2215
2316
24- # <HINT> Create a Car Model model `class CarModel(models.Model):`:
25- # - Many-To-One relationship to Car Make model (One Car Make has many
26- # Car Models, using ForeignKey field)
27- # - Name
28- # - Type (CharField with a choices argument to provide limited choices
29- # such as Sedan, SUV, WAGON, etc.)
30- # - Year (IntegerField) with min value 2015 and max value 2023
31- # - Any other fields you would like to include in car model
32- # - __str__ method to print a car make object
33-
17+ # Car Model model
3418class CarModel (models .Model ):
35- car_make = models .ForeignKey (CarMake , on_delete = models .CASCADE ) # Many-to-One relationship
19+ # Many-to-One relationship (one CarMake has many CarModels)
20+ car_make = models .ForeignKey (
21+ CarMake ,
22+ on_delete = models .CASCADE ,
23+ )
3624 name = models .CharField (max_length = 100 )
25+
3726 CAR_TYPES = [
3827 ('SEDAN' , 'Sedan' ),
3928 ('SUV' , 'SUV' ),
4029 ('WAGON' , 'Wagon' ),
4130 # Add more choices as required
4231 ]
43- type = models .CharField (max_length = 10 , choices = CAR_TYPES , default = 'SUV' )
44- year = models .IntegerField (default = 2023 ,
32+
33+ type = models .CharField (
34+ max_length = 10 ,
35+ choices = CAR_TYPES ,
36+ default = 'SUV' ,
37+ )
38+
39+ year = models .IntegerField (
40+ default = 2023 ,
4541 validators = [
4642 MaxValueValidator (2023 ),
47- MinValueValidator (2015 )
48- ])
49- # Other fields as needed
43+ MinValueValidator (2015 ),
44+ ],
45+ )
5046
5147 def __str__ (self ):
52- return self .name # Return the name as the string representation
48+ return self .name
0 commit comments