Commit cf9ca778 authored by rachbit's avatar rachbit

created app bookshelf and implemented models

parent 7ec30b9a
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 MinLengthValidator, RegexValidator
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()
def __str__(self):
return '{} {}'.format(self.first_name, self.last_name)
class Books(models.Model):
title = models.CharField(max_length=100)
author = models.ForeignKey(Author,on_delete=models.CASCADE,default="")
publisher = models.CharField(max_length=100)
year_published = models.IntegerField(validators=[MinValueValidator(0),MaxValueValidator(2023)])
ISBN = models.CharField(primary_key=True, max_length=13,validators=[MinLengthValidator(13), RegexValidator(r'^\d{1,10}$')])
def __str__(self):
return '{}'.format(self.title)
from django.test import TestCase
# Create your tests here.
from django.urls import path
from .views import index
urlpatterns = [
path('', index, name='index'),
]
# This might be needed, depending on your Django version
app_name = "bookshelf"
from django.shortcuts import render
from django.http import HttpResponse
# Create your views here.
def index(request):
return HttpResponse('bookshelf view')
...@@ -40,6 +40,8 @@ INSTALLED_APPS = [ ...@@ -40,6 +40,8 @@ INSTALLED_APPS = [
'django.contrib.sessions', 'django.contrib.sessions',
'django.contrib.messages', 'django.contrib.messages',
'django.contrib.staticfiles', 'django.contrib.staticfiles',
'bookshelf',
] ]
MIDDLEWARE = [ MIDDLEWARE = [
......
...@@ -14,8 +14,9 @@ Including another URLconf ...@@ -14,8 +14,9 @@ Including another URLconf
2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) 2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
""" """
from django.contrib import admin from django.contrib import admin
from django.urls import path from django.urls import path, include
urlpatterns = [ urlpatterns = [
path('admin/', admin.site.urls), path('admin/', admin.site.urls),
path('',include('bookshelf.urls', namespace='bookshelf')),
] ]
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