23.03.2017 Views

wilamowski-b-m-irwin-j-d-industrial-communication-systems-2011

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Interactive Web Site Design Using Python Script 63-7<br />

FIGURE 63.11<br />

Customized administration Web site.<br />

63.3.8 Customize the Admin Site<br />

The application already has the basic functions of a database, such as add, change, and delete. But it is<br />

not good enough for application. The following steps will make the database much more powerful:<br />

1. Add the Python code below into the models.py file. This will use the document names as the<br />

links to visit the related documents.<br />

def __ unicode __ (self):<br />

return self.document _ name<br />

2. Edit the admin.py file using the code below. This will list all the document information row by<br />

row. In the table, all the document information can be ordered by either document name, author<br />

name, or submission date.<br />

from paper _ system.documents.models import Document<br />

from django.contrib import admin<br />

class DocumentAdmin(admin.ModelAdmin):<br />

list _ display = ('document _ name','document _ auth','sub _ date')<br />

admin.site.register(Document, DocumentAdmin)<br />

3. Add code below to admin.py file. This will create sidebar used to filter the listed document<br />

information by specified date.<br />

list _ filter = ['sub _ date']<br />

4. Add code below to admin.py file. This will add a search box at the top of the document list,<br />

which can be used to search document information by author name.<br />

search _ fields = ['document _ auth']<br />

5. Add code below to admin.py file. This will add hierarchical navigation by submission date.<br />

date _ hierarchy = 'sub _ date'<br />

With all the above customization, the new administration Web site is as shown in Figure 63.11.<br />

63.4 Conclusion<br />

The above example built a framework for a database-driven Web site server. It includes interface design<br />

and basic SQL operations, such as create, search, add, and delete. As one may notice, the entire project<br />

is done in a considerably limited time and with very few codes.<br />

By conclusion, the major features of Django can be described as follows [B08]:<br />

• Object-relational mapper: By defining the data models in Python, Django can offer an efficient<br />

and dynamic database access APIs for free.<br />

• Automatic admin interface: Django does all the work of creating interfaces automatically, avoiding<br />

tedious and duplicated coding.<br />

© <strong>2011</strong> by Taylor and Francis Group, LLC

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!