Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Renos incomplete cars and brands #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion car_app/car_app/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'cars_and_brands'
'cars_and_brands',
]

MIDDLEWARE = [
Expand Down
3 changes: 2 additions & 1 deletion car_app/car_app/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import path
from django.urls import path, include

urlpatterns = [
path('admin/', admin.site.urls),
path('brand/', include('cars_and_brands.urls'))
]
Empty file.
32 changes: 32 additions & 0 deletions car_app/cars_and_brands/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Generated by Django 2.1.3 on 2021-07-14 00:44

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

initial = True

dependencies = [
]

operations = [
migrations.CreateModel(
name='Brand',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('brand', models.CharField(max_length=200)),
],
),
migrations.CreateModel(
name='Car',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('model', models.CharField(max_length=200)),
('year', models.IntegerField()),
('color', models.CharField(max_length=200)),
('brand', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='cars', to='cars_and_brands.Brand')),
],
),
]
20 changes: 20 additions & 0 deletions car_app/cars_and_brands/models.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
from django.db import models
from django.db.models.base import Model
from django.db.models.fields.related import ForeignKey

# Create your models here.


class Brand(models.Model):
brand = models.CharField(max_length=200)

def __str__(self):
return f'Brand: {self.brand}'


class Car(models.Model):
brand = models.ForeignKey(
Brand, on_delete=models.CASCADE, related_name='cars')
model = models.CharField(max_length=200)
year = models.IntegerField()
color = models.CharField(max_length=200)

def __str__(self):
return (f"brand: {self.brand}, model: {self.model}, year: {self.year}, color: {self.color}")
10 changes: 10 additions & 0 deletions car_app/cars_and_brands/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from django.urls import path
from . import views

urlpatterns = [
path('', views.brand_list, name='brand_list'),
path('<int:brand_id>', views.model_list, name='model_list'),
path('<int:brand_id>/add_brand', views.add_brand, name='add_brand'),
path('<int:brand_id>/delete_brand', views.delete_brand, name='delete_brand'),
path('<int:brand_id>/edit_car', views.edit_car, name='edit_car'),
]
13 changes: 13 additions & 0 deletions car_app/cars_and_brands/views.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
from django.shortcuts import render
from .models import Brand, Car

# Create your views here.
# # urlpatterns = [
# path('', views.brand_list, name='brand_list'),
# path('<int:brand_id>', views.model_list, name='model_list'),
# path('<int:brand_id>/add_brand', views.add_brand, name='add_brand'),
# path('<int:brand_id>/delete_brand', views.delete_brand, name='delete_brand'),
# path('<int:brand_id>/edit_car', views.edit_car, name='edit_car'),
# ]


def brand_list(request):
brands = Brand.objects.all()
return render(request, )
25 changes: 25 additions & 0 deletions car_app/seeds.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from cars_and_brands.models import Brand, Car

brand1 = Brand(brand='Volvo')
brand1.save()

brand2 = Brand(brand='Chevy')
brand2.save()

brand3 = Brand(brand='Ford')
brand3.save()

brand4 = Brand(brand='Subaru')
brand4.save()

car1 = Car(brand=brand1, model='XYZ', year=2020, color='red')
car1.save()

car2 = Car(brand=brand2, model='truck', year=2010, color='white')
car2.save()

car3 = Car(brand=brand3, model='car', year=2000, color='blue')
car3.save()

car4 = Car(brand=brand4, model='outback', year=2001, color='yellow')
car4.save()