Commit 64be1536 authored by Ysobel Vera's avatar Ysobel Vera

Built Author and Books classes in models.py and edited admin.py of bookshelf app

+Created Author and Books classes. The Author class contains fields to keep track of the author's first and last name, age, nationality, and bio. The Books class contains fields to keep track of the book's title, author, publisher, publishing year, ISBN, and blurb.
+The admin.py file was edited to create admin panels for the 2 classes in models.py
- haven't removed the placeholder for views.py under bookshelf. This will be edited later on.
parent b8dfe587
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 4.1.6 on 2023-03-27 13:57
from django.db import migrations, models
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=100)),
('last_name', models.CharField(max_length=100)),
('age', models.IntegerField(max_length=3)),
('nationality', models.CharField(max_length=100)),
('bio', models.TextField(max_length=700)),
],
),
]
# Generated by Django 4.1.6 on 2023-03-27 14:04
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('bookshelf', '0001_initial'),
]
operations = [
migrations.CreateModel(
name='Books',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('title', models.CharField(max_length=100)),
('publisher', models.CharField(max_length=100)),
('year_published', models.IntegerField(max_length=4)),
('ISBN', models.IntegerField(max_length=13)),
('blurb', models.TextField(max_length=200)),
('author', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='bookshelf.author')),
],
),
]
# Generated by Django 4.1.6 on 2023-03-27 14:09
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('bookshelf', '0002_books'),
]
operations = [
migrations.AlterField(
model_name='author',
name='age',
field=models.IntegerField(),
),
migrations.AlterField(
model_name='books',
name='ISBN',
field=models.IntegerField(),
),
migrations.AlterField(
model_name='books',
name='year_published',
field=models.IntegerField(),
),
]
from django.db import models
# Create your models here.
class Author(models.Model):
first_name = models.CharField(max_length=100)
last_name = models.CharField(max_length=100)
age = models.IntegerField()
nationality = models.CharField(max_length=100)
bio = models. TextField(max_length=700)
class Books(models.Model):
title = models.CharField(max_length=100)
author = models.ForeignKey(Author, on_delete=models.CASCADE)
publisher = models.CharField(max_length=100)
year_published = models.IntegerField()
ISBN = models.IntegerField()
blurb = models.TextField(max_length=200)
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