Commit b8545f6c authored by Brendan Fausto's avatar Brendan Fausto

Added models, admin, and started template

parent f0a7544c
SECRET_KEY = 'django-insecure-inccf6=49=8i5&tn!8k*my320--+$w89v*t&l*8&yd91%m0qp3'
\ No newline at end of file
from django.contrib import admin
from .models import Books, Authors
class BookAdmin(admin.ModelAdmin):
model = Books
list_display = ('title','author','publisher','year_published','isbn','blurb',)
class AuthorAdmin(admin.ModelAdmin):
model = Authors
list_display = ('first_name','last_name','age','nationality','bio',)
admin.site.register(Books, BookAdmin)
admin.site.register(Authors, AuthorAdmin)
# Register your models here.
# Generated by Django 4.1.6 on 2023-03-30 08:27
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='Authors',
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(validators=[django.core.validators.MaxValueValidator(200), django.core.validators.MinValueValidator(1)])),
('nationality', models.CharField(max_length=255)),
('bio', models.CharField(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.IntegerField(validators=[django.core.validators.MaxValueValidator(2023), django.core.validators.MinValueValidator(1000)])),
('isbn', models.CharField(max_length=13, validators=[django.core.validators.MinLengthValidator(13)])),
('blurb', models.CharField(max_length=800)),
('author', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='bookshelf.authors')),
],
),
]
from django.db import models
from django.core.validators import MaxValueValidator, MinValueValidator, MinLengthValidator
import datetime
# Create your models here.
class Books(models.Model):
title = models.CharField(max_length=255)
author = models.ForeignKey('Authors', on_delete=models.PROTECT)
publisher = models.CharField(max_length=255)
year_published = models.IntegerField(validators = [MaxValueValidator(2023), MinValueValidator(1000)])
isbn = models.CharField(max_length=13, validators = [MinLengthValidator(13)])
blurb = models.CharField(max_length=800)
class Authors(models.Model):
first_name = models.CharField(max_length=255)
last_name = models.CharField(max_length=255)
age = models.IntegerField(validators = [MaxValueValidator(200), MinValueValidator(1)])
nationality = models.CharField(max_length=255)
bio = models.CharField(max_length=700)
\ No newline at end of file
# about/urls.py
from django.urls import path
from .views import index
urlpatterns = [
path('', index, name='index'),
]
app_name = "bookshelf" # for proper namespacing in urls, otherwise will result in errors
\ No newline at end of file
......@@ -9,8 +9,13 @@ https://docs.djangoproject.com/en/4.1/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/4.1/ref/settings/
"""
import os
from pathlib import Path
from dotenv import load_dotenv
load_dotenv()
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
......@@ -20,7 +25,7 @@ BASE_DIR = Path(__file__).resolve().parent.parent
# See https://docs.djangoproject.com/en/4.1/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'django-insecure-inccf6=49=8i5&tn!8k*my320--+$w89v*t&l*8&yd91%m0qp3'
SECRET_KEY = os.getenv('SECRET_KEY')
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
......@@ -37,6 +42,7 @@ INSTALLED_APPS = [
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'bookshelf'
]
MIDDLEWARE = [
......
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