Skip to content

Commit 748b1ab

Browse files
committed
Simplify first example to not use a mapping
1 parent da0ba1c commit 748b1ab

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

docs/index.rst

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ It all starts with a CSV file you'd like to load into your database. This librar
6868

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

121118
.. code-block:: bash
122119

0 commit comments

Comments
 (0)