PY THON/DJANGO Credit: www.djangoproject.com
Finish your cataloguing app
With a tear in his eye, Matt Holder finishes up our cataloguing database app by adding search and export functionality.
OUR EXPERT
Matt Holder has been a fan of the open source methodology for over two decades and uses Linux and other tools where possible. In his spare time, Matt enjoys listening to music and reading.
OUICK TIP
More featurepacked source code for this project can be downloaded from https:// github.com/ mattmole/LXF-Django-Project.
In this series of articles, we’ve been working on a cataloguing application, where magazines, I newspapers and corresponding articles can be added, stored and eventually searched. In parts one and two, we introduced Django, described some basic database theory, created our database models, explored the built-in shell, added some URLs and created some views and HTML pages to view output from the software. We also explored the admin interface, which allows data to be added and deleted.
In this final article, we’re exploring the forms functionality, which allows for HTML forms to be added to our web pages to provide data entry, and then we’re creating a page to enable us to search the database and return articles, authors and publications.
A completed project can be downloaded from GitHub (see the QuickTip, below-left) and contains the functionality discussed in the three articles and more.
First, let’s create a search page. This will consist of a URL to link against the Python view, a Python view to provide the functionality to search the database, and an HTML page to display results. This will also use the forms functionality to provide the text and other fields before taking the input and using it in search queries, and then the data will be output and displayed in the browser, along with links to open the original record.
Before entering the URL into the browser, make sure you enter python ../manage.py runserver into the terminal, then the built-in web server is invoked.