Book Image

Mastering Django: Core

By : Nigel George
Book Image

Mastering Django: Core

By: Nigel George

Overview of this book

Mastering Django: Core is a completely revised and updated version of the original Django Book, written by Adrian Holovaty and Jacob Kaplan-Moss - the creators of Django. The main goal of this book is to make you a Django expert. By reading this book, you’ll learn the skills needed to develop powerful websites quickly, with code that is clean and easy to maintain. This book is also a programmer’s manual that provides complete coverage of the current Long Term Support (LTS) version of Django. For developers creating applications for commercial and business critical deployments, Mastering Django: Core provides a complete, up-to-date resource for Django 1.8LTS with a stable code-base, security fixes and support out to 2018.
Table of Contents (33 chapters)
Mastering Django: Core
Credits
About the Author
www.PacktPub.com
Preface
Free Chapter
1
Introduction to Django and Getting Started

Adding your models to the admin site


There's one crucial part we haven't done yet. Let's add our own models to the admin site, so we can add, change and delete objects in our custom database tables using this nice interface. We'll continue the books example from Chapter 4, Models, where we defined three models: Publisher, Author, and Book. Within the books directory (mysite/books), startapp should have created a file called admin.py, if not, simply create one yourself and type in the following lines of code:

from django.contrib import admin 
from .models import Publisher, Author, Book 
 
admin.site.register(Publisher) 
admin.site.register(Author) 
admin.site.register(Book) 

This code tells the Django admin site to offer an interface for each of these models. Once you've done this, go to your admin home page in your web browser (http://127.0.0.1:8000/admin/), and you should see a Books section with links for Authors, Books, and Publishers. (You might have to stop...