Commit 914ac61a authored by Eldon Dagdag's avatar Eldon Dagdag

Created bookshelf app and built models

parent dcf49af9
from django.contrib import admin
from .models import Author, Books
class AuthorAdmin(admin.ModelAdmin):
model = Author
class BooksAdmin(admin.ModelAdmin):
model = Books
admin.site.register(Author, AuthorAdmin)
admin.site.register(Books, BooksAdmin)
from django.apps import AppConfig
class BookshelfConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'bookshelf'
# Generated by Django 4.1.7 on 2023-03-28 07:17
import django.core.validators
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(default='', max_length=255)),
('last_name', models.CharField(default='', max_length=255)),
('age', models.PositiveIntegerField()),
('nationality', models.CharField(default='', max_length=255)),
('bio', models.TextField(blank=True, default='', 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(default='', max_length=255)),
('publisher', models.CharField(default='', max_length=255)),
('year_published', models.PositiveIntegerField()),
('ISBN', models.PositiveBigIntegerField(validators=[django.core.validators.MinLengthValidator(1000000000000), django.core.validators.MaxValueValidator(9999999999999)])),
('blurb', models.TextField(default='', max_length=1000)),
('author', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='bookshelf.author')),
],
),
]
from django.db import models
from django.core.validators import MinLengthValidator, MaxValueValidator
class Author(models.Model):
first_name = models.CharField(max_length=255, default='')
last_name = models.CharField(max_length=255, default='')
age = models.PositiveIntegerField()
nationality = models.CharField(max_length=255, default='')
bio = models.TextField(max_length=700, blank=True, default='')
def __str__(self):
return '{} {}'.format(self.first_name, self.last_name)
class Books(models.Model):
title = models.CharField(max_length=255, default='')
author = models.ForeignKey(Author, on_delete=models.CASCADE)
publisher = models.CharField(max_length=255, default='')
year_published = models.PositiveIntegerField()
ISBN = models.PositiveBigIntegerField(validators=[MinLengthValidator(1000000000000), MaxValueValidator(9999999999999)])
blurb = models.TextField(max_length=1000, default='')
def __str__(self):
return '{} by {}'.format(self.title, self.author)
from django.test import TestCase
# Create your tests here.
from django.urls import path
from .views import index
urlpatterns = [
path('', index, name='index')
]
app_name = "bookshelf"
\ No newline at end of file
from django.shortcuts import render
from django.http import HttpResponse
def index(request):
return HttpResponse('Hello World!')
\ No newline at end of file
......@@ -41,6 +41,7 @@ INSTALLED_APPS = [
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'bookshelf',
]
MIDDLEWARE = [
......
......@@ -14,8 +14,9 @@ Including another URLconf
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 include, path
urlpatterns = [
path('bookshelf/', include('bookshelf.urls', namespace="bookshelf")),
path('admin/', admin.site.urls),
]
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