Skip to content

Commit

Permalink
build and register Car Model and Car Make models
Browse files Browse the repository at this point in the history
  • Loading branch information
seymoneg committed Dec 9, 2023
1 parent f5950c4 commit d188b06
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 2 deletions.
Binary file modified server/db.sqlite3
Binary file not shown.
13 changes: 12 additions & 1 deletion server/djangoapp/admin.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@
from django.contrib import admin
# from .models import related models
from .models import CarModel, CarMake


# Register your models here.

# CarModelInline class
class CarModelInline(admin.StackedInline):
model = CarModel
extra = 2

# CarModelAdmin class
class CarModelAdmin(admin.ModelAdmin):
fields = ["make", "name", "dealer_id", "car_type", "year"]

# CarMakeAdmin class with CarModelInline
class CarMakeAdmin(admin.ModelAdmin):
inlines = [CarModelInline]
fields = ["name", "description"]


# Register models here
admin.site.register(CarModel, CarModelAdmin)
admin.site.register(CarMake, CarMakeAdmin)
35 changes: 34 additions & 1 deletion server/djangoapp/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@
# - 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(null=False, max_length=100, default="Make")
description = models.CharField(max_length=500)

def __str__(self):
return "Name: " + self.name + ", Description: " + self.description


# <HINT> Create a Car Model model `class CarModel(models.Model):`:
Expand All @@ -19,7 +25,34 @@
# - Year (DateField)
# - Any other fields you would like to include in car model
# - __str__ method to print a car make object

class CarModel(models.Model):
# defining car choices
SEDAN = "Sedan"
SUV = "SUV"
WAGON = "Wagon"
MINIVAN = "Minivan"
TRUCK = "Truck"

CAR_TYPES = [
(SEDAN, "Sedan"),
(SUV, "SUV"),
(WAGON, "Wagon"),
(MINIVAN, "Minivan"),
(TRUCK, "Truck")
]

make = models.ForeignKey(CarMake, on_delete=models.CASCADE)
name = models.CharField(null=False, max_length=100, default="Model")
dealer_id = models.IntegerField(default=1,primary_key=True)
car_type = models.CharField(null=False, max_length=50, choices=CAR_TYPES,
default=SEDAN
)
year = models.DateField(null=True)

def __str__(self):
return "Name: " + self.name + ", Type: " + self.car_type + ", Year: " + str(self.year)



# <HINT> Create a plain Python class `CarDealer` to hold dealer data

Expand Down

0 comments on commit d188b06

Please sign in to comment.