Commit 17b85c10 authored by Julia Anishka's avatar Julia Anishka

registered author and books models

parent 4f40ae22
from django.contrib import admin from django.contrib import admin
from .models import Author, Books
class BooksInLine(admin.TabularInline):
model = Books
class AuthorAdmin(admin.ModelAdmin):
model = Author
list_display = ('first_name', 'last_name', 'age', 'nationality')
search_fields = ['first_name', 'last_name']
inlines = [BooksInLine]
class BooksAdmin(admin.ModelAdmin):
list_display = ('title', 'author', 'publisher', 'year_published', 'ISBN')
def get_title(self, obj):
return obj.books.title
get_title.short_description = "Book Title"
admin.site.register(Author, AuthorAdmin)
admin.site.register(Books, BooksAdmin)
\ No newline at end of file
...@@ -26,6 +26,7 @@ class Books(models.Model): ...@@ -26,6 +26,7 @@ class Books(models.Model):
) )
ISBN = models.CharField(max_length = 13, validators = [MinValueValidator(13), verify_int]) ISBN = models.CharField(max_length = 13, validators = [MinValueValidator(13), verify_int])
blurb = models.CharField(max_length = 200, validators = [MinValueValidator(100)]) blurb = models.CharField(max_length = 200, validators = [MinValueValidator(100)])
def __str__(self): def __str__(self):
return self.title return 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