Importing data from a local Excel file

Another popular format to store tabular data is an Excel spread sheet. In this recipe, we will import movies from a file of this format.

Getting ready

Let's start with the movies app that we created in the previous recipe. Install the xlrd package to read Excel files, as follows:

(project_env)$ pip install xlrd

How to do it...

Follow these steps to create and use a management command that imports movies from a local XLS file:

  1. If you haven't done that, in the movies app, create a management directory and then a commands directory in the new management directory. Put the empty __init__.py files in both the new directories to make them Python packages.
  2. Add the import_movies_from_xls.py file with the following content: ...

Get Web Development with Django Cookbook - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.