Commit 25677754 authored by rachbit's avatar rachbit

created admin panel

parent cf9ca778
from django.contrib import admin from django.contrib import admin
from .models import Author, Book
# Register your models here. class AuthorAdmin(admin.ModelAdmin):
model = Author
list_display = ("last_name","first_name","nationality","bio")
search_fields = ("first_name","last_name")
class BooksAdmin(admin.ModelAdmin):
model = Book
list_display = ("title","author","blurb","publisher","year_published","ISBN")
search_fields = ("title","author","year_published","publisher","ISBN")
# registering the model and the admin is what tells
# Django that admin pages must be generated for the models specified
admin.site.register(Author, AuthorAdmin)
admin.site.register(Book, BooksAdmin)
# Generated by Django 3.2 on 2023-03-28 12: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(max_length=100)),
('last_name', models.CharField(max_length=100)),
('age', models.IntegerField()),
('nationality', models.CharField(max_length=100)),
('bio', models.TextField()),
],
),
migrations.CreateModel(
name='Books',
fields=[
('title', models.CharField(max_length=100)),
('publisher', models.CharField(max_length=100)),
('year_published', models.CharField(max_length=4, validators=[django.core.validators.RegexValidator('^\\d{1,10}$')])),
('ISBN', models.CharField(max_length=13, primary_key=True, serialize=False, validators=[django.core.validators.MinLengthValidator(13), django.core.validators.RegexValidator('^\\d{1,10}$')])),
('author', models.ForeignKey(default='', on_delete=django.db.models.deletion.CASCADE, to='bookshelf.author')),
],
),
]
# Generated by Django 3.2 on 2023-03-28 12:55
import django.core.validators
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('bookshelf', '0001_initial'),
]
operations = [
migrations.CreateModel(
name='Book',
fields=[
('title', models.CharField(max_length=100)),
('publisher', models.CharField(max_length=100)),
('year_published', models.CharField(max_length=4, validators=[django.core.validators.RegexValidator('^\\d{1,10}$')])),
('ISBN', models.CharField(max_length=13, primary_key=True, serialize=False, validators=[django.core.validators.MinLengthValidator(13), django.core.validators.RegexValidator('^\\d{1,10}$')])),
('blurb', models.CharField(max_length=200)),
('author', models.ForeignKey(default='', on_delete=django.db.models.deletion.CASCADE, to='bookshelf.author')),
],
),
migrations.DeleteModel(
name='Books',
),
]
...@@ -12,13 +12,14 @@ class Author(models.Model): ...@@ -12,13 +12,14 @@ class Author(models.Model):
def __str__(self): def __str__(self):
return '{} {}'.format(self.first_name, self.last_name) return '{} {}'.format(self.first_name, self.last_name)
class Books(models.Model): class Book(models.Model):
title = models.CharField(max_length=100) title = models.CharField(max_length=100)
author = models.ForeignKey(Author,on_delete=models.CASCADE,default="") author = models.ForeignKey(Author,on_delete=models.CASCADE,default="")
publisher = models.CharField(max_length=100) publisher = models.CharField(max_length=100)
year_published = models.IntegerField(validators=[MinValueValidator(0),MaxValueValidator(2023)]) year_published = models.CharField(max_length=4, validators=[RegexValidator(r'^\d{1,10}$')])
ISBN = models.CharField(primary_key=True, max_length=13,validators=[MinLengthValidator(13), RegexValidator(r'^\d{1,10}$')]) ISBN = models.CharField(primary_key=True, max_length=13,validators=[MinLengthValidator(13), RegexValidator(r'^\d{1,10}$')])
blurb = models.CharField(max_length=200)
def __str__(self): def __str__(self):
return '{}'.format(self.title) return '{}'.format(self.title)
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