Skip to content

Commit

Permalink
Builded CarMake and CarModel models
Browse files Browse the repository at this point in the history
  • Loading branch information
gokhanduzel committed Dec 7, 2023
1 parent b036f52 commit 04e28f4
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 2 deletions.
Binary file modified server/db.sqlite3
Binary file not shown.
15 changes: 13 additions & 2 deletions 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 CarMake, CarModel

# Register your models here.

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

# CarModelAdmin class
class CarModelAdmin(admin.ModelAdmin):
fields = ['name', 'car_type']

# CarMakeAdmin class with CarModelInline

class CarMakeAdmin(admin.ModelAdmin):
fields = ['name', 'description']
inlines = [CarModelInline
]
# Register models here
admin.site.register(CarMake, CarMakeAdmin)
admin.site.register(CarModel, CarModelAdmin)

31 changes: 31 additions & 0 deletions 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(max_length=100)
description = models.CharField(max_length=500)

def __str__(self):
return f"name: {self.name}, description: {self.description}"


# <HINT> Create a Car Model model `class CarModel(models.Model):`:
Expand All @@ -19,6 +25,31 @@
# - 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):

SEDAN = 'sedan'
SUV = 'suv'
WAGON = 'wagon'
COUPE = 'coupe'
CABRIO = 'cabrio'

CAR_TYPES = [
(SEDAN, 'Sedan'),
(SUV, 'SUV'),
(WAGON, 'Wagon'),
(COUPE, 'Coupe'),
(CABRIO, 'Cabrio')
]


car_make = models.ForeignKey(CarMake, on_delete=models.CASCADE)
name = models.CharField(max_length=100)
dealer_id = models.IntegerField()
car_type = models.CharField(max_length=20, choices=CAR_TYPES, default=SEDAN)
year = models.DateField()

def __str__(self):
return f"name:{self.name} type:{self.car_type} make:{self.car_make.name}"


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

0 comments on commit 04e28f4

Please sign in to comment.