Commit f22139d3 authored by Jenica Vizmanos's avatar Jenica Vizmanos

Created a bookshelf app with proper Author and Book models and admin setup

parent d5f4ebcd
from django.contrib import admin
from .models import Author, Book
class AuthorAdmin(admin.ModelAdmin):
model = Author
search_fields = ('first_name', 'last_name',)
list_display = ('first_name', 'last_name', 'nationality',)
list_filter = ('first_name', 'last_name', 'nationality',)
class BookAdmin(admin.ModelAdmin):
model = Book
search_fields = ('title', 'publisher',)
list_display = ('title', 'publisher', 'year_published', 'ISBN',)
list_filter = ('title', 'publisher', 'year_published',)
admin.site.register(Author, AuthorAdmin)
admin.site.register(Book, BookAdmin)
from django.apps import AppConfig
class BookshelfConfig(AppConfig):
default_auto_field = "django.db.models.BigAutoField"
name = "bookshelf"
# Generated by Django 4.1.6 on 2023-03-28 06:33
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.IntegerField(default=0)),
("nationality", models.CharField(default="", max_length=255)),
("bio", models.TextField(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(default=0)),
(
"ISBN",
models.PositiveBigIntegerField(
default=0,
validators=[
django.core.validators.MaxValueValidator(9999999999999)
],
),
),
("blurb", models.TextField(default="", max_length=800)),
(
"author",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
to="bookshelf.author",
),
),
],
),
]
# Generated by Django 4.1.6 on 2023-03-28 06:44
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
("bookshelf", "0001_initial"),
]
operations = [
migrations.RenameModel(old_name="Books", new_name="Book",),
]
from django.db import models
from django.core.validators import MaxValueValidator
class Author(models.Model):
first_name = models.CharField(max_length=255, default='')
last_name = models.CharField(max_length=255, default='')
age = models.IntegerField(default=0)
nationality = models.CharField(max_length=255, default='')
bio = models.TextField(max_length=700, default='')
def __str__(self):
return 'Author Name: {} {}'.format(self.first_name, self.last_name)
class Book(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(default=0)
ISBN = models.PositiveBigIntegerField(validators=[MaxValueValidator(9999999999999)], default=0)
blurb = models.TextField(max_length=800, default='')
def __str__(self):
return 'Book Name: {}'.format(self.title)
\ No newline at end of file
from django.test import TestCase
# Create your tests here.
from django.shortcuts import render
# Create your views here.
...@@ -40,6 +40,7 @@ INSTALLED_APPS = [ ...@@ -40,6 +40,7 @@ INSTALLED_APPS = [
"django.contrib.sessions", "django.contrib.sessions",
"django.contrib.messages", "django.contrib.messages",
"django.contrib.staticfiles", "django.contrib.staticfiles",
"bookshelf",
] ]
MIDDLEWARE = [ MIDDLEWARE = [
......
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