11# Uncomment the following imports before adding the Model code
22
33from django .db import models
4- from django .utils .timezone import now
54from django .core .validators import MaxValueValidator , MinValueValidator
65
76
87# Create your models here.
98class CarMake (models .Model ):
9+ """
10+ Represents a car make (e.g., Toyota, Ford, etc.).
11+
12+ The CarMake model stores information about the car manufacturer,
13+ including the name, description, country of origin, and the date
14+ the brand was established.
15+
16+ Attributes:
17+ name (str): The name of the car manufacturer.
18+ description (str): A description of the car manufacturer.
19+ country_of_origin (str, optional): The country where the car manufacturer is based.
20+ established_date (date, optional): The date when the car manufacturer was established.
21+ """
22+
1023 name = models .CharField (max_length = 100 )
1124 description = models .TextField ()
12- country_of_origin = models .CharField (max_length = 100 , blank = True , null = True ) # Optional: field for the country of origin
13- established_date = models .DateField (blank = True , null = True ) # Optional: field for the year when the brand was established
25+ country_of_origin = models .CharField (max_length = 100 , blank = True , null = True )
26+ established_date = models .DateField (blank = True , null = True )
1427
1528 def __str__ (self ):
1629 return self .name # Return the name as the string representation
1730
1831
1932class CarModel (models .Model ):
20- car_make = models .ForeignKey (CarMake , on_delete = models .CASCADE ) # Many-to-One relationship
33+ """
34+ Represents a car model associated with a specific car make (e.g., Camry, Mustang, etc.).
35+
36+ The CarModel model stores details about a specific model of a car,
37+ including its make, type, year, engine type, fuel type, color, price,
38+ mileage, horsepower, and transmission.
39+
40+ Attributes:
41+ car_make (ForeignKey): A reference to the CarMake model representing the car's manufacturer.
42+ name (str): The name of the car model (e.g., Camry, A-Class).
43+ type (str): The type of the car (e.g., Sedan, SUV, Wagon).
44+ year (int): The year the car model was manufactured.
45+ engine_type (str, optional): The type of engine in the car.
46+ fuel_type (str): The fuel type used by the car (e.g., Petrol, Diesel, Electric, Hybrid).
47+ color (str, optional): The color of the car.
48+ price (decimal, optional): The price of the car.
49+ mileage (float, optional): The mileage of the car.
50+ horsepower (int, optional): The horsepower of the car's engine.
51+ transmission (str): The type of transmission in the car (e.g., Automatic, Manual).
52+ """
53+ car_make = models .ForeignKey (CarMake , on_delete = models .CASCADE )
2154 name = models .CharField (max_length = 100 )
2255 CAR_TYPES = [
2356 ('SEDAN' , 'Sedan' ),
@@ -31,12 +64,25 @@ class CarModel(models.Model):
3164 MaxValueValidator (2023 ),
3265 MinValueValidator (2015 )
3366 ])
34- engine_type = models .CharField (max_length = 50 , blank = True , null = True ) # Engine type (e.g., V6, V8, Electric)
35- fuel_type = models .CharField (max_length = 20 , choices = [('PETROL' , 'Petrol' ), ('DIESEL' , 'Diesel' ), ('ELECTRIC' , 'Electric' ), ('HYBRID' , 'Hybrid' )], default = 'PETROL' ) # Fuel type
36- color = models .CharField (max_length = 30 , blank = True , null = True ) # Car color
37- price = models .DecimalField (max_digits = 10 , decimal_places = 2 , blank = True , null = True ) # Price of the car model
38- mileage = models .FloatField (blank = True , null = True ) # Mileage (miles per gallon or km per liter)
39- horsepower = models .IntegerField (blank = True , null = True ) # Engine horsepower
40- transmission = models .CharField (max_length = 20 , choices = [('AUTOMATIC' , 'Automatic' ), ('MANUAL' , 'Manual' )], default = 'AUTOMATIC' ) # Transmission type
67+ engine_type = models .CharField (max_length = 50 , blank = True , null = True )
68+ fuel_type = models .CharField (
69+ max_length = 20 ,
70+ choices = [
71+ ('PETROL' , 'Petrol' ),
72+ ('DIESEL' , 'Diesel' ),
73+ ('ELECTRIC' , 'Electric' ),
74+ ('HYBRID' , 'Hybrid' )
75+ ],
76+ default = 'PETROL'
77+ )
78+ color = models .CharField (max_length = 30 , blank = True , null = True )
79+ price = models .DecimalField (max_digits = 10 , decimal_places = 2 , blank = True , null = True )
80+ mileage = models .FloatField (blank = True , null = True )
81+ horsepower = models .IntegerField (blank = True , null = True )
82+ transmission = models .CharField (
83+ max_length = 20 ,
84+ choices = [('AUTOMATIC' , 'Automatic' ), ('MANUAL' , 'Manual' )],
85+ default = 'AUTOMATIC'
86+ )
4187 def __str__ (self ):
42- return self .name # Return the name as the string representation
88+ return self .name
0 commit comments