Commit ee782a7a authored by Eldon Dagdag's avatar Eldon Dagdag

Populated Author and Book models

parent 914ac61a
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
class BooksAdmin(admin.ModelAdmin): class BookAdmin(admin.ModelAdmin):
model = Books model = Book
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 07:50
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('bookshelf', '0001_initial'),
]
operations = [
migrations.RenameModel(
old_name='Books',
new_name='Book',
),
]
# Generated by Django 4.1.7 on 2023-03-28 08:11
import django.core.validators
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('bookshelf', '0002_rename_books_book'),
]
operations = [
migrations.AlterField(
model_name='book',
name='ISBN',
field=models.PositiveBigIntegerField(validators=[django.core.validators.MinValueValidator(1000000000000), django.core.validators.MaxValueValidator(9999999999999)]),
),
]
from django.db import models from django.db import models
from django.core.validators import MinLengthValidator, MaxValueValidator from django.core.validators import MinValueValidator, MaxValueValidator
class Author(models.Model): class Author(models.Model):
first_name = models.CharField(max_length=255, default='') first_name = models.CharField(max_length=255, default='')
...@@ -11,12 +11,12 @@ class Author(models.Model): ...@@ -11,12 +11,12 @@ class Author(models.Model):
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=255, default='') title = models.CharField(max_length=255, default='')
author = models.ForeignKey(Author, on_delete=models.CASCADE) author = models.ForeignKey(Author, on_delete=models.CASCADE)
publisher = models.CharField(max_length=255, default='') publisher = models.CharField(max_length=255, default='')
year_published = models.PositiveIntegerField() year_published = models.PositiveIntegerField()
ISBN = models.PositiveBigIntegerField(validators=[MinLengthValidator(1000000000000), MaxValueValidator(9999999999999)]) ISBN = models.PositiveBigIntegerField(validators=[MinValueValidator(1000000000000), MaxValueValidator(9999999999999)])
blurb = models.TextField(max_length=1000, default='') blurb = models.TextField(max_length=1000, default='')
def __str__(self): 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