File tree Expand file tree Collapse file tree 1 file changed +6
-9
lines changed Expand file tree Collapse file tree 1 file changed +6
-9
lines changed Original file line number Diff line number Diff line change @@ -68,7 +68,7 @@ It all starts with a CSV file you'd like to load into your database. This librar
68
68
69
69
.. code-block :: text
70
70
71
- NAME,NUMBER,DATE
71
+ name,number,date
72
72
ben,1,2012-01-01
73
73
joe,2,2012-01-02
74
74
jane,3,2012-01-03
@@ -85,7 +85,7 @@ A Django model that corresponds to the data might look something like this. It s
85
85
class Person (models .Model ):
86
86
name = models.CharField(max_length = 500 )
87
87
number = models.IntegerField(null = True )
88
- dt = models.DateField(null = True )
88
+ date = models.DateField(null = True )
89
89
objects = CopyManager()
90
90
91
91
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
109
109
class Command (BaseCommand ):
110
110
111
111
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' )
118
115
119
- Run your loader and that's it .
116
+ Run your loader.
120
117
121
118
.. code-block :: bash
122
119
You can’t perform that action at this time.
0 commit comments