Code a cataloguing application in Python
Strap in kids! Using Python and the Django framework, Matt Holder can help you create a web-based cataloguing application.
DJANGO
Credit: www.djangoproject.com
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.
QUICK TIP
More featurepacked source code for this project can be downloaded from https://github.com/mattmole/LXF-Django-Project
Part One!
Don’t miss next issue, subscribe on page 16!
We’re going to start the process of creating an application that can be used to catalogue and search magazine articles, with the idea that once filled in, you won’t need to rifle through that massive pile of old issues to find a particular article. Consideration will be made to the fact that a publisher can have multiple magazines assigned, articles can appear in multiple magazines and that a magazine can have multiple issues.
The technology we are using to accomplish this is called Django. This is a library for the Python programming language, which allows web applications to be created. Similar to Python itself, Django comes with ‘batteries included’ and has some of the features we require built-in with its provided admin interface.
Django operates using the Model-View-Controller (MVC) paradigm, which means that the program is split into these three areas. Model refers to the data and how it is stored in a database. Django supports a wide range of databases, but for our purposes, a simple SQlite database suffices. Database access is via a database ORM (object-relational mapping), which means that Django provides Python objects to interact with the database and doesn’t require SQL statements to be used directly. The second part of MVC is View. This means how the application displays the information stored in the database and how it is interacted with. Finally, Controller refers to the logic that ties together how the database stores the data (Model) and how it is displayed (View).
The ORM used by Django provides methods that can be used to follow the relationships defined by our model. For example, we could use a method to display all articles where a certain tag is defined or display all magazines registered to a publisher.