Chapter 4. A Car Rental App

For this chapter, our hypothetical client is a car rental firm. They want us to create a website that their customers can visit, look at the available inventory of cars, and finally book one of those cars. The client also wants an admin panel where they can manage the inventory and booking requests.

We will be creating this web app in (drum rolls) Django! You should be confident enough in Django by now that the frontend of the web app will not be a challenge for us. The focus of this chapter will be on customizing the Django built-in admin app to fit the requirements of our client. Most of the time when you need an administration panel for the web apps you create, you can do pretty much everything you need just by customizing the Django admin. Sometimes the requirements are complex enough that you need to create a custom administration panel, but that is seldom the case. So the knowledge we gain here will prove extremely useful to you in your web development career.

The main takeaways from this chapter will be as follows:

  • Customizing Django admin model forms
  • Adding custom filters to the admin objects list page
  • Overriding and customizing Django admin templates

Code pack

As I have mentioned, by now you should have a firm grasp of creating the components for a basic web app, including the views, templates, models, and URL configurations, so we will not be discussing these parts of the web app in this chapter. The code pack for this chapter is thus much bigger that the previous ones. I have created all the models and some of the views, templates, and URLs. We will mostly be focusing on how to tame the Django admin app to suit our needs.

I could not think of a fancy name for this project, so I just called the project carrental. As always, create a new virtual environment, install Django in this environment, and run the migrate command to initialize the database. For this project, we need to install one more Python package, Pillow, which is an image manipulation library for Python. To install it, run the following command with the virtual environment activated:

> pip install Pillow

This might take a minute or so as some compilation may be required. Installing Pillow is a bit more complicated because it relies on third-party libraries. If the install command fails for you, take a look at the documentation on installing Pillow at https://pillow.readthedocs.org/en/3.0.x/installation.html. This page has step-by-step guides for each operating system, and following the guide there, you should be able to install Pillow easily. Just remember that you need the library to run and work on the car rental application.

Once Pillow has been installed, run the development server using the runserver command and open up the web app at http://127.0.0.1:8000. You should see the following page:

Code pack
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.143.203.96