Commit b8616515 authored by Albert Gagalac's avatar Albert Gagalac

Implemented admin panel

parent 51713d1d
......@@ -9,6 +9,7 @@ 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
......
......@@ -14,8 +14,9 @@ Including another URLconf
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import path
from django.urls import include, path
urlpatterns = [
path("admin/", admin.site.urls),
path("bookshelf/", include ('bookshelf.urls', namespace="bookshelf")),
path("admin/", admin.site.urls)
]
# Register your models here.
from django.contrib import admin
from .models import Author, Book
# Register your models here.
class AuthorAdmin(admin.ModelAdmin):
model = Author
search_fields = ('first_name', 'last_name',)
class BookAdmin(admin.ModelAdmin):
model = Book
search_fields = ('title', 'ISBN')
admin.site.register(Author, AuthorAdmin)
admin.site.register(Book, BookAdmin)
# Generated by Django 4.1.7 on 2023-03-28 05:41
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="Author",
fields=[
(
"id",
models.BigAutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("first_name", models.CharField(default="", max_length=100)),
("last_name", models.CharField(default="", max_length=100)),
("age", models.PositiveIntegerField(default=0)),
("nationality", models.CharField(default="", max_length=100)),
("bio", models.TextField(default="", 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(default="", max_length=100)),
("publisher", models.CharField(default="", max_length=100)),
(
"ISBN",
models.PositiveIntegerField(
validators=[
django.core.validators.RegexValidator(
"^[0-9]*$", message="Only numbers are allowed"
),
django.core.validators.MinLengthValidator(13),
django.core.validators.MaxLengthValidator(13),
]
),
),
("blurb", models.TextField(default="", max_length=200)),
(
"author",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
to="bookshelf.author",
),
),
],
),
]
......@@ -4,8 +4,8 @@ from django.core.validators import RegexValidator, MinLengthValidator, MaxLength
# Create your models here.
class Author(models.Model):
first_name = models.CharField(default="")
last_name = models.CharField(default="")
first_name = models.CharField(default="", max_length=100)
last_name = models.CharField(default="", max_length=100)
age = models.PositiveIntegerField(default=0)
nationality = models.CharField(default="", max_length=100)
bio = models.TextField(default="", max_length = 700)
......@@ -16,10 +16,10 @@ class Author(models.Model):
def get_absolute_url(self):
return reverse('author', args=[str(self.name)])
class Books(models.Model):
title = models.CharField(default="")
class Book(models.Model):
title = models.CharField(default="", max_length=100)
author = models.ForeignKey(Author, on_delete=models.CASCADE)
publisher = models.CharField(default="")
publisher = models.CharField(default="", max_length=100)
ISBN = models.PositiveIntegerField(validators=
[RegexValidator(r'^[0-9]*$',
message='Only numbers are allowed'),
......@@ -31,4 +31,4 @@ class Books(models.Model):
return '{}'.format(self.title)
def get_absolute_url(self):
return reverse('books', args=[str(self.name)])
return reverse('book', args=[str(self.name)])
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
# Create your views here.
def index(request):
return HttpResponse('Hello World! This came from the index view')
\ 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