Commit 6dbbe2d7 authored by Nics De Vega's avatar Nics De Vega

fixed admin panel, modified and populated models for bookshelf

parent d19136ea
from django.contrib import admin from django.contrib import admin
from .models import Author,Books from .models import Author,Book
class AuthorAdmin(admin.ModelAdmin): class AuthorAdmin(admin.ModelAdmin):
model = Author model = Author
list_dsiplay = ("first_name","last_name","age","nationality","bio") list_display = ("first_name","last_name","age","nationality","bio")
search_fields = ("first_name","last_names") search_fields = ("first_name","last_name")
list_filter = ("first_name","last_name","nationality") list_filter = ("first_name","last_name","nationality")
class BooksAdmin(admin.ModelAdmin): class BookAdmin(admin.ModelAdmin):
model = Books model = Book
list_display = ("title","author","publisher","year_published","ISBN","blurb") list_display = ("title","author","publisher","year_published","ISBN","blurb")
search_fields = ("title","author","publisher","year_published","ISBN") search_fields = ("title","author","publisher","year_published","ISBN")
list_filter = ("author","publisher","year_published") list_filter = ("author","publisher","year_published")
admin.site.register(Author,AuthorAdmin) admin.site.register(Author,AuthorAdmin)
admin.site.register(Books,BooksAdmin) admin.site.register(Book,BookAdmin)
# Generated by Django 4.1.7 on 2023-03-28 06:19
import django.core.validators
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('bookshelf', '0001_initial'),
]
operations = [
migrations.AlterField(
model_name='author',
name='age',
field=models.PositiveIntegerField(),
),
migrations.AlterField(
model_name='books',
name='ISBN',
field=models.IntegerField(default=0, validators=[django.core.validators.MaxValueValidator(9999999999999)]),
),
migrations.AlterField(
model_name='books',
name='blurb',
field=models.TextField(default='', max_length=700, validators=[django.core.validators.MinLengthValidator(100)]),
),
migrations.AlterField(
model_name='books',
name='year_published',
field=models.IntegerField(validators=[django.core.validators.MaxValueValidator(2023)]),
),
]
# Generated by Django 4.1.7 on 2023-03-28 06:37
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('bookshelf', '0002_alter_author_age_alter_books_isbn_alter_books_blurb_and_more'),
]
operations = [
migrations.RenameModel(
old_name='Books',
new_name='Book',
),
]
# Generated by Django 4.1.7 on 2023-03-28 07:47
import django.core.validators
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('bookshelf', '0003_rename_books_book'),
]
operations = [
migrations.AlterField(
model_name='book',
name='ISBN',
field=models.IntegerField(validators=[django.core.validators.MaxValueValidator(9999999999999), django.core.validators.MinValueValidator(1000000000000)]),
),
migrations.AlterField(
model_name='book',
name='year_published',
field=models.PositiveIntegerField(validators=[django.core.validators.MaxValueValidator(2023)]),
),
]
# Generated by Django 4.1.7 on 2023-03-28 07:51
import django.core.validators
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('bookshelf', '0004_alter_book_isbn_alter_book_year_published'),
]
operations = [
migrations.AlterField(
model_name='book',
name='ISBN',
field=models.IntegerField(unique=True, validators=[django.core.validators.MaxValueValidator(9999999999999), django.core.validators.MinValueValidator(1000000000000)]),
),
]
from django.db import models from django.db import models
from django.core.validators import MinValueValidator,MaxValueValidator, MinLengthValidator
class Author (models.Model): class Author(models.Model):
first_name = models.CharField(max_length=100,default="") first_name = models.CharField(max_length=100,default="")
last_name = models.CharField(max_length=100,default="") last_name = models.CharField(max_length=100,default="")
age = models.IntegerField() age = models.PositiveIntegerField()
nationality = models.CharField(max_length=100,default="") nationality = models.CharField(max_length=100,default="")
bio = models.TextField(max_length=700,default="") bio = models.TextField(max_length=700,default="")
def __str__(self): def __str__(self):
return '{} {}'.format(self.first_name, self.last_name) return '{} {}'.format(self.first_name, self.last_name)
class Books(models.Model): class Book(models.Model):
title = models.CharField(max_length=100,default="") title = models.CharField(max_length=100,default="")
author = models.ForeignKey(Author,on_delete=models.CASCADE) author = models.ForeignKey(Author,on_delete=models.CASCADE)
publisher = models.CharField(max_length=100, default="") publisher = models.CharField(max_length=100, default="")
year_published = models.IntegerField(default=0) year_published = models.PositiveIntegerField(validators=[MaxValueValidator(2023)])
ISBN = models.IntegerField(default=0) ISBN = models.IntegerField(unique=True, validators=[MaxValueValidator(9999999999999),MinValueValidator(1000000000000)])
blurb = models.TextField(max_length=700,default ="") blurb = models.TextField(validators=[MinLengthValidator(100)],max_length=700,default ="")
def __str__(self): def __str__(self):
return '{} by {}'.format(self.title, self.author) return '{} by {}'.format(self.title, self.author)
\ No newline at end of file
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