Importing data from a local CSV file
The comma-separated values (CSV) format is probably the simplest way to store tabular data in a text file. In this recipe, we will create a management command that imports data from CSV to a Django database. We will need a CSV list of movies with a title, URL, and release year. You can easily create such files with Excel, Calc, or another spreadsheet application.
Getting ready
Create a movies
app with the Movie
model containing the following fields: title
, url
, and release_year
. Place the app under INSTALLED_APPS
in the settings.
How to do it...
Follow these steps to create and use a management command that imports movies from a local CSV file:
- In the
movies
app, create amanagement
directory and then acommands ...
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.