Commit 2cfdc0cc authored by MJoshBen's avatar MJoshBen

Models and Admin Panels have been coded and created

parent 4b039386
from django.contrib import admin 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)
# Register your models here.
from django.db import models from django.db import models
# Create your models here. # Create your models here.
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=20)
bio = models.TextField(max_length=700)
def __str__(self):
return '{}, {}'.format(self.last_name, self.first_name)
class Books(models.Model):
title = models.CharField(max_length=100)
author = models.ForeignKey(
Author,
on_delete=models.CASCADE
)
publisher = models.CharField(max_length=100)
year_published = models.IntegerField()
ISBN = models.IntegerField()
blurb = models.TextField()
def __str__(self):
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