Commit 73418642 authored by Star Neptune R. Sy's avatar Star Neptune R. Sy

admin panel done, model linked, ready to populate

parent 404a8ebd
# app/admin.py
from django.contrib import admin from django.contrib import admin
from .models import Author,Book
# Register your models here.
class AuthorAdmin(admin.ModelAdmin):
list_display = ('first_name', 'last_name', 'age', 'nationality')
search_fields = ('first_name', 'last_name',)
list_filter = ('first_name', 'last_name',)
class BookAdmin(admin.ModelAdmin):
list_display = ('title', 'author', 'year_published', 'publisher', 'ISBN',)
search_fields = ('title', 'author', 'ISBN',)
list_filter = ('title', 'author', 'year_published', 'publisher',)
# registering the model and the admin is what tells
# Django that admin pages must be generated for the models specified
admin.site.register(Author, AuthorAdmin)
admin.site.register(Book, BookAdmin)
# Generated by Django 3.2 on 2023-03-28 12:11
import datetime
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=50)),
('last_name', models.CharField(blank=True, max_length=50)),
('age', models.IntegerField(blank=True)),
('nationality', models.CharField(max_length=50)),
('bio', models.TextField(blank=True)),
],
),
migrations.CreateModel(
name='Book',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('title', models.CharField(blank=True, max_length=50)),
('publisher', models.CharField(blank=True, max_length=50)),
('year_published', models.DateField(verbose_name=datetime.datetime(2023, 3, 28, 20, 11, 53, 417993))),
('ISBN', models.CharField(default='0000000000000', max_length=50, unique=True)),
('blurb', models.TextField(blank=True)),
('author', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='bookshelf.author')),
],
),
]
...@@ -8,6 +8,9 @@ class Author(models.Model): ...@@ -8,6 +8,9 @@ class Author(models.Model):
nationality = models.CharField(max_length=50) nationality = models.CharField(max_length=50)
bio = models.TextField(blank=True,) bio = models.TextField(blank=True,)
def __str__(self):
return "{} {}".format(self.first_name, self.last_name)
class Book(models.Model): class Book(models.Model):
title = models.CharField(max_length=50, blank=True) title = models.CharField(max_length=50, blank=True)
...@@ -19,3 +22,6 @@ class Book(models.Model): ...@@ -19,3 +22,6 @@ class Book(models.Model):
year_published = models.DateField(datetime.datetime.today()) year_published = models.DateField(datetime.datetime.today())
ISBN = models.CharField(max_length=50, unique=True, blank=False, default="0000000000000") ISBN = models.CharField(max_length=50, unique=True, blank=False, default="0000000000000")
blurb = models.TextField(blank=True,) blurb = models.TextField(blank=True,)
def __str__(self):
return self.title
\ No newline at end of file
...@@ -41,6 +41,7 @@ INSTALLED_APPS = [ ...@@ -41,6 +41,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