Commit 39a03f63 authored by EJ Mejilla's avatar EJ Mejilla

Created the bookshelf app, created models and populated the database

parent 2c7b4b08
from django.contrib import admin
from .models import Author, Books
class AuthorAdmin(admin.ModelAdmin):
model = Author
list_display = ('first_name', 'last_name', 'age', 'nationality')
class BooksAdmin(admin.ModelAdmin):
model = Books
list_display = ('title', 'author', 'year_published', 'ISBN')
admin.site.register(Author, AuthorAdmin)
admin.site.register(Books, BooksAdmin)
# Register your models here.
from django.apps import AppConfig
class BookshelfConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'bookshelf'
# Generated by Django 3.2 on 2023-03-28 09:53
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='Author',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('first_name', models.CharField(blank=True, max_length=200)),
('last_name', models.CharField(blank=True, max_length=200)),
('age', models.IntegerField(default=0)),
('nationality', models.CharField(blank=True, max_length=50)),
('bio', models.TextField(blank=True, max_length=700)),
],
),
migrations.CreateModel(
name='Books',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('title', models.CharField(blank=True, max_length=200)),
('publisher', models.CharField(blank=True, max_length=200)),
('year_published', models.IntegerField(default=0)),
('ISBN', models.IntegerField(default=0)),
('blurb', models.TextField(blank=True, max_length=1000)),
('author', models.ForeignKey(blank=True, on_delete=django.db.models.deletion.CASCADE, to='bookshelf.author')),
],
),
]
from django.db import models
class Author(models.Model):
first_name = models.CharField(max_length=200, blank=True)
last_name = models.CharField(max_length=200, blank=True)
age = models.IntegerField(default=0)
nationality = models.CharField(max_length=50, blank=True)
bio = models.TextField(max_length=700, blank=True)
def __str__(self):
return f"{self.first_name} {self.last_name}"
class Books(models.Model):
title = models.CharField(max_length=200, blank=True)
author = models.ForeignKey(Author, blank=True, on_delete=models.CASCADE)
publisher = models.CharField(max_length=200, blank=True)
year_published = models.IntegerField(default=0)
ISBN = models.IntegerField(default=0)
blurb = models.TextField(max_length=1000, blank=True)
from django.test import TestCase
# Create your tests here.
# bookshelf/urls.py
from django.urls import path
from .views import index
urlpatterns = [
path('', index, name='index'),
]
app_name = "bookshelf"
# bookshelf/views.py
from django.http import HttpResponse
def index(request):
return HttpResponse('Hello World! This came from the index view')
...@@ -39,6 +39,7 @@ INSTALLED_APPS = [ ...@@ -39,6 +39,7 @@ INSTALLED_APPS = [
'django.contrib.sessions', 'django.contrib.sessions',
'django.contrib.messages', 'django.contrib.messages',
'django.contrib.staticfiles', 'django.contrib.staticfiles',
'bookshelf',
] ]
MIDDLEWARE = [ MIDDLEWARE = [
......
...@@ -14,8 +14,9 @@ Including another URLconf ...@@ -14,8 +14,9 @@ Including another URLconf
2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) 2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
""" """
from django.contrib import admin from django.contrib import admin
from django.urls import path from django.urls import include, path
urlpatterns = [ urlpatterns = [
path('admin/', admin.site.urls), path('admin/', admin.site.urls),
path('bookshelf/', include('bookshelf.urls', namespace="bookshelf"))
] ]
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment