Database Populated

parent 175f835b
...@@ -4,9 +4,11 @@ from .models import Author, Books ...@@ -4,9 +4,11 @@ from .models import Author, Books
# Register your models here. # Register your models here.
class AuthorAdmin(admin.ModelAdmin): class AuthorAdmin(admin.ModelAdmin):
model = Author model = Author
list_display = ('first_name', 'last_name', 'bio')
class BooksAdmin(admin.ModelAdmin): class BooksAdmin(admin.ModelAdmin):
model = Books model = Books
list_display = ('title', 'author', 'publisher', 'year_published')
admin.site.register(Author, AuthorAdmin) admin.site.register(Author, AuthorAdmin)
admin.site.register(Books, BooksAdmin) admin.site.register(Books, BooksAdmin)
\ No newline at end of file
# Generated by Django 3.2 on 2023-03-27 17:26
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=50)),
('last_name', models.CharField(max_length=50)),
('age', models.IntegerField()),
('nationality', models.CharField(max_length=50)),
('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=1000)),
('publisher', models.CharField(max_length=1000)),
('year_published', models.IntegerField()),
('ISBN', models.CharField(max_length=13)),
('blurb', models.TextField()),
('author', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='bookshelf.author')),
],
),
]
...@@ -12,12 +12,15 @@ class Author(models.Model): ...@@ -12,12 +12,15 @@ class Author(models.Model):
return '{} {}'.format(self.first_name, self.last_name) return '{} {}'.format(self.first_name, self.last_name)
class Books(models.Model): class Books(models.Model):
title = models.CharField() title = models.CharField(max_length=1000)
author = models.ForeignKey( author = models.ForeignKey(
Author, Author,
on_delete=models.PROTECT on_delete=models.PROTECT
) )
publisher = models.CharField() publisher = models.CharField(max_length=1000)
year_published = models.IntegerField() year_published = models.IntegerField()
ISBN = models.IntegerField(max_length=13) ISBN = models.CharField(max_length=13)
blurb = models.TextField() blurb = models.TextField()
def __str__(self):
return '{}'.format(self.title)
\ No newline at end of file
from django.shortcuts import render from django.shortcuts import render
from django.http import HttpResponse
# Create your views here. # Create your views here.
def index(request):
return HttpResponse("Hello World!")
\ 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