Commit 93252b9b authored by Jayson Lim's avatar Jayson Lim

Implemented Admin panel

parent ea2f399c
from django.contrib import admin from django.contrib import admin
from .models import Author, Books
# Register your models here. class AuthorAdmin(admin.ModelAdmin):
model = Author
class BooksAdmin(admin.ModelAdmin):
model = Books
admin.site.register(Author, AuthorAdmin)
admin.site.register(Books, BooksAdmin)
# Generated by Django 3.2 on 2023-03-28 08:00
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('bookshelf', '0001_initial'),
]
operations = [
migrations.RenameModel(
old_name='Books',
new_name='Book',
),
]
...@@ -7,6 +7,9 @@ class Author(models.Model): ...@@ -7,6 +7,9 @@ class Author(models.Model):
nationality = models.CharField(max_length=50, default="") nationality = models.CharField(max_length=50, default="")
bio = models.TextField(max_length=700) bio = models.TextField(max_length=700)
def __str__(self):
return '{}, {}'.format(self.first_name, self.last_name)
class Books(models.Model): class Books(models.Model):
title = models.CharField(max_length=50, default="") title = models.CharField(max_length=50, default="")
author = models.ForeignKey(Author, on_delete=models.CASCADE, related_name='books') author = models.ForeignKey(Author, on_delete=models.CASCADE, related_name='books')
...@@ -15,3 +18,6 @@ class Books(models.Model): ...@@ -15,3 +18,6 @@ class Books(models.Model):
ISBN = models.CharField(max_length=13) ISBN = models.CharField(max_length=13)
blurb = models.TextField() blurb = models.TextField()
def __str__(self):
return self.title
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