Skip to content

Commit

Permalink
Simplify first example to not use a mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
palewire committed Oct 21, 2017
1 parent da0ba1c commit 748b1ab
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ It all starts with a CSV file you'd like to load into your database. This librar

.. code-block:: text
NAME,NUMBER,DATE
name,number,date
ben,1,2012-01-01
joe,2,2012-01-02
jane,3,2012-01-03
Expand All @@ -85,7 +85,7 @@ A Django model that corresponds to the data might look something like this. It s
class Person(models.Model):
name = models.CharField(max_length=500)
number = models.IntegerField(null=True)
dt = models.DateField(null=True)
date = models.DateField(null=True)
objects = CopyManager()
If the model hasn't been created in your database, that needs to happen.
Expand All @@ -109,14 +109,11 @@ Here's how to create a script to import CSV data into the model. Our favorite wa
class Command(BaseCommand):
def handle(self, *args, **kwargs):
Person.objects.from_csv(
# The path to your CSV
'/path/to/my/data.csv',
# And a dict mapping the model fields to CSV headers
dict(name='NAME', number='NUMBER', dt='DATE')
)
# Since the CSV headers match the model fields,
# you only need to provide the file's path
Person.objects.from_csv('/path/to/my/import.csv')
Run your loader and that's it.
Run your loader.

.. code-block:: bash
Expand Down

0 comments on commit 748b1ab

Please sign in to comment.