Commit fe433cfb authored by Sharmaine Chua's avatar Sharmaine Chua

did some minor changes in the models and populated the database

parent bb051541
from django.contrib import admin
from .models import Author, Book
from .models import Author, Books
class AuthorAdmin(admin.ModelAdmin):
model = Author
......@@ -9,10 +9,10 @@ class AuthorAdmin(admin.ModelAdmin):
list_filter = ('first_name', 'last_name', 'age', 'nationality',)
class BooksAdmin(admin.ModelAdmin):
model = Book
model = Books
list_display = ('title', 'author', 'publisher', 'year_published', 'ISBN', 'blurb',)
search_fields = ('title', 'author', 'publisher', 'year_published', 'ISBN',)
list_filter = ('title', 'author', 'publisher', 'year_published',)
admin.site.register(Author, AuthorAdmin)
admin.site.register(Book, BooksAdmin)
admin.site.register(Books, BooksAdmin)
# Generated by Django 3.2 on 2023-03-28 11:40
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('bookshelf', '0002_rename_books_book'),
]
operations = [
migrations.AlterField(
model_name='author',
name='nationality',
field=models.CharField(default='', max_length=50),
),
]
# Generated by Django 4.1.6 on 2023-03-28 11:57
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('bookshelf', '0003_alter_author_nationality'),
]
operations = [
migrations.RenameModel(
old_name='Book',
new_name='Books',
),
]
# Generated by Django 4.1.6 on 2023-03-28 12:18
import bookshelf.models
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('bookshelf', '0004_rename_book_books'),
]
operations = [
migrations.AlterField(
model_name='books',
name='ISBN',
field=models.IntegerField(default=0, unique=True, validators=[bookshelf.models.validate_isbn]),
),
]
......@@ -9,18 +9,18 @@ class Author(models.Model):
first_name = models.CharField(max_length=100,default="")
last_name = models.CharField(max_length=100,default="")
age = models.IntegerField(default=0)
nationality = models.CharField(max_length=50,unique=True,default="")
nationality = models.CharField(max_length=50,default="")
bio = models.TextField(max_length=700,default="")
def __str__(self):
return '{} {}'.format(self.first_name, self.last_name)
class Book(models.Model):
class Books(models.Model):
title = models.CharField(max_length=50,default="")
author = models.ForeignKey(Author,on_delete=models.CASCADE)
publisher = models.CharField(max_length=100,default="")
year_published = models.IntegerField(default=2023)
ISBN = models.IntegerField(validators=[validate_isbn],default=0000000000000)
ISBN = models.IntegerField(validators=[validate_isbn],unique=True,default=0000000000000)
blurb = models.TextField(max_length=200,default="")
def __str__(self):
......
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