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.
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
Follow these steps to create and use a management command that imports movies from a local XLS file:
If you haven't done that, in the
movies
app, create amanagement
directory and then acommands
directory in the newmanagement
directory. Put the empty__init__.py
files in both the new directories to make them Python packages.Add the
import_movies_from_xls.py
file with the following content:# movies/management/commands/import_movies_from_xls.py # -*- coding: UTF-8 -*- from __future__ import unicode_literals import xlrd from django.utils.six.moves import range from django.core.management.base import BaseCommand from movies.models...