diff --git a/server/db.sqlite3 b/server/db.sqlite3 index 24221ca598..1d34d38a3b 100644 Binary files a/server/db.sqlite3 and b/server/db.sqlite3 differ diff --git a/server/djangoapp/admin.py b/server/djangoapp/admin.py index b1039e16b8..b034033070 100644 --- a/server/djangoapp/admin.py +++ b/server/djangoapp/admin.py @@ -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) + diff --git a/server/djangoapp/models.py b/server/djangoapp/models.py index 27d96f4eff..5596c32b7a 100644 --- a/server/djangoapp/models.py +++ b/server/djangoapp/models.py @@ -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}" # Create a Car Model model `class CarModel(models.Model):`: @@ -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}" # Create a plain Python class `CarDealer` to hold dealer data