Commit 51713d1d authored by Albert Gagalac's avatar Albert Gagalac

Added bookshelf app + author & book models

parent 2cbca803
......@@ -11,6 +11,9 @@ https://docs.djangoproject.com/en/4.1/ref/settings/
"""
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 +23,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-vae3s*l&73wjrxfc=e!2yw8)yr7(h($^*v7q)uw%*5+1ddqg$-"
SECRET_KEY = os.getenv('SECRET_KEY')
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
......@@ -37,6 +40,7 @@ INSTALLED_APPS = [
"django.contrib.sessions",
"django.contrib.messages",
"django.contrib.staticfiles",
"bookshelf"
]
MIDDLEWARE = [
......
from django.contrib import admin
# Register your models here.
from django.apps import AppConfig
class BookshelfConfig(AppConfig):
default_auto_field = "django.db.models.BigAutoField"
name = "bookshelf"
from django.db import models
from django.core.validators import RegexValidator, MinLengthValidator, MaxLengthValidator
# Create your models here.
class Author(models.Model):
first_name = models.CharField(default="")
last_name = models.CharField(default="")
age = models.PositiveIntegerField(default=0)
nationality = models.CharField(default="", max_length=100)
bio = models.TextField(default="", max_length = 700)
def __str__(self):
return '{} {}'.format(self.first_name, self.last_name)
def get_absolute_url(self):
return reverse('author', args=[str(self.name)])
class Books(models.Model):
title = models.CharField(default="")
author = models.ForeignKey(Author, on_delete=models.CASCADE)
publisher = models.CharField(default="")
ISBN = models.PositiveIntegerField(validators=
[RegexValidator(r'^[0-9]*$',
message='Only numbers are allowed'),
MinLengthValidator(13),
MaxLengthValidator(13)])
blurb = models.TextField(default="", max_length = 200)
def __str__(self):
return '{}'.format(self.title)
def get_absolute_url(self):
return reverse('books', args=[str(self.name)])
from django.test import TestCase
# Create your tests here.
from django.shortcuts import render
# Create your views here.
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