Commit d0c4552a authored by justin's avatar justin

Created bookshelf app, Author and Books models and corresponding Admin panels

parent d516727b
from django.contrib import admin
from models import Author, Books
class AuthorAdmin(admin.ModelAdmin):
model = Author
list_display = (
"first_name",
"last_name",
"age",
"nationality",
"bio",
)
search_fields = (
"first_name",
"last_name",
)
list_filter = ("nationality",)
class BooksAdmin(admin.ModelAdmin):
model = Books
list_display = (
"title",
"author",
"publisher",
"year_published",
"isbn",
)
search_fields = (
"title",
"author",
"publisher",
"isbn",
)
list_filter = (
"publisher",
"author",
)
class BooksInline(admin.StackedInline):
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'
from django.db import models
from django.core.validators import MaxLengthValidator
class Author(models.Model):
first_name = models.CharField(max_length=255)
last_name = models.CharField(max_length=255)
age = models.PositiveIntegerField()
nationality = models.CharField(max_length=255)
bio = models.TextField(max_length=700)
def __str__(self):
return f"{self.first_name} {self.last_name}"
class Books(models.Model):
title = models.CharField(max_length=255)
author = models.ForeignKey(Author, on_delete=models.CASCADE)
publisher = models.CharField(
max_length=255,
default="Unknown",
)
year_published = models.IntegerField(default=0)
isbn = models.PositiveBigIntegerField(validators=[MaxLengthValidator(13)])
def __str__(self):
return self.title
from django.test import TestCase
# Create your tests here.
from django.shortcuts import render
# Create your views here.
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