Built the App and Models; Created the Admin Panel

parent e2f15e2c
from django.contrib import admin
from .models import Author, Books
class AuthorAdmin(admin.ModelAdmin):
model = Author
class BooksAdmin(admin.ModelAdmin):
model = Books
admin.site.register(Author, AuthorAdmin)
admin.site.register(Books, BooksAdmin)
\ No newline at end of file
from django.apps import AppConfig
class BookshelfConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'bookshelf'
from django.db import models
class Author(models.Model):
first_name = models.CharField(max_length=255, default="")
last_name = models.CharField(max_length=255, default="")
age = models.IntegerField(default=0)
nationality = models.CharField(max_length=255, default="")
bio = models.TextField(max_length=700, default="")
class Books(models.Model):
title = models.CharField(max_length=255, default="")
author = models.ForeignKey(Author, on_delete=models.CASCADE)
publisher = models.CharField(max_length=255, default="")
year_published = models.IntegerField(default=0)
ISBN = models.IntegerField(default=0)
blurb = models.TextField(max_length=200, default="")
\ No newline at end of file
from django.test import TestCase
# Create your tests here.
from django.urls import path
from .views import index
urlpatterns = [
path('', index, name='index'),
]
app_name = "bookshelf"
\ No newline at end of file
from django.shortcuts import render
from django.http import HttpResponse
def index(request):
return HttpResponse("")
\ No newline at end of file
...@@ -41,6 +41,7 @@ INSTALLED_APPS = [ ...@@ -41,6 +41,7 @@ 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 include, path
urlpatterns = [ urlpatterns = [
path('bookshelf/', include('bookshelf.urls', namespace="bookshelf")),
path('admin/', admin.site.urls), path('admin/', admin.site.urls),
] ]
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