Commit 590b516e authored by Ian Rafael T. Aragoza's avatar Ian Rafael T. Aragoza

Built and populated bookshelf app models, Author and Book.

parent b9addaf6
Pipeline #2986 failed with stages
from django.contrib import admin from django.contrib import admin
from .models import Author, Book
# Register your models here. # Register your models here.
class AuthorAdmin(admin.ModelAdmin):
model = Author
search_fields = ('first_name', 'last_name',)
list_display = ('last_name', 'first_name', 'nationality', 'age', 'bio',)
list_filter = ('nationality', 'age',)
class BookAdmin(admin.ModelAdmin):
model = Book
search_fields = ('title', 'author',)
list_display = ('title', 'author', 'publisher', 'year_published', 'ISBN', 'blurb')
list_filter = ('publisher', 'year_published',)
admin.site.register(Author, AuthorAdmin)
admin.site.register(Book, BookAdmin)
# Generated by Django 4.1.7 on 2023-03-27 15:59
import django.core.validators
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(max_length=255)),
('last_name', models.CharField(max_length=255)),
('age', models.IntegerField()),
('nationality', models.CharField(max_length=255)),
('bio', models.TextField(max_length=700)),
],
),
migrations.CreateModel(
name='Books',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('title', models.CharField(max_length=255)),
('publisher', models.CharField(max_length=255)),
('year_published', models.PositiveIntegerField(validators=[django.core.validators.MinValueValidator(1), django.core.validators.MaxValueValidator(2023)])),
('ISBN', models.IntegerField(validators=[django.core.validators.MinLengthValidator(13), django.core.validators.MaxLengthValidator(13)])),
('blurb', models.TextField()),
('author', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='books', to='bookshelf.author')),
],
),
]
# Generated by Django 4.1.7 on 2023-03-27 16:13
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-27 16:22
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.IntegerField(validators=[django.core.validators.MinValueValidator(9780000000000), django.core.validators.MaxValueValidator(9789999999999)]),
),
]
from django.db import models from django.db import models
from django.urls import reverse
from django.core.validators import MaxValueValidator, MinValueValidator
# Create your models here. # Create your models here.
class Author(models.Model):
first_name = models.CharField(max_length=255)
last_name = models.CharField(max_length=255)
age = models.IntegerField()
nationality = models.CharField(max_length=255)
bio = models.TextField(max_length=700)
def __str__(self):
return '{} {}'.format(self.first_name, self.last_name)
def get_absolute_url(self):
return reverse('author_detail', args=[str(self.last_name)])
class Book(models.Model):
title = models.CharField(max_length=255)
author = models.ForeignKey(Author, on_delete=models.CASCADE, related_name='books')
publisher = models.CharField(max_length=255)
year_published = models.PositiveIntegerField(validators=[MinValueValidator(1), MaxValueValidator(2023)])
ISBN = models.IntegerField(validators=[MinValueValidator(9780000000000), MaxValueValidator(9789999999999)])
blurb = models.TextField()
def __str__(self):
return '{}'.format(self.title)
def get_absolute_url(self):
return reverse('book_detail', args=[str(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