title: Import csv data into database in Django Admin
body: <p>I've tried to import a csv file into a database by tweaking the modelform inside the admin doing this:</p>
  
  <p>models.py:</p>
  
  <pre><code>class Data(models.Model):
      place = models.ForeignKey(Places)
      time = models.DateTimeField()
      data_1 = models.DecimalField(max_digits=3, decimal_places=1)
      data_2 = models.DecimalField(max_digits=3, decimal_places=1)
      data_3 = models.DecimalField(max_digits=4, decimal_places=1)
  </code></pre>
  
  <p>Forms.py:</p>
  
  <pre><code>import csv
  class DataImport(ModelForm):
      file_to_import = forms.FileField()
  
      class Meta:
          model = Data
          fields = ("file_to_import", "place")
  
      def save(self, commit=False, *args, **kwargs):
          form_input = DataImport()
          self.place = self.cleaned_data['place']
          file_csv = request.FILES['file_to_import']
          datafile = open(file_csv, 'rb')
          records = csv.reader(datafile)
          for line in records:
              self.time = line[1]
              self.data_1 = line[2]
              self.data_2 = line[3]
              self.data_3 = line[4]
              form_input.save()
          datafile.close()
  </code></pre>
  
  <p>Admin.py:</p>
  
  <pre><code>class DataAdmin(admin.ModelAdmin):
      list_display = ("place", "time")
      form = DataImport
  
  admin.site.register(Data, DataAdmin)
  </code></pre>
  
  <p>But i'm stuck trying to import the file i put in "file_to_import" field. Getting AttributeError in forms.py : 'function' object has no attribute 'FILES'.</p>
  
  <p>What i'm doing wrong?</p>