title: Why do i get an Attribute Error when trying to assign the file to a Model.form??)
body: <p>In my django project i am trying to generate a new edited file out of existing ones, so when i am editing the file and trying to save it to a new model called FileField it says   <strong>AttributeError at /my_blanks/2/
  'str' object has no attribute 'get'</strong> . I need to save or asign my edited document and the name of it to my Model.forms  so i can handle it later (download, delete), Can you Help me please?   </p>
  
  <p>To solve my task i use DocEdited model then pass it to forms.py</p>
  
  <p><strong>models.py</strong>     </p>
  
  <pre><code># -*- coding: utf-8 -*-
  from __future__ import unicode_literals
  from django.db import models
  from django.core.files.storage import FileSystemStorage
  from my_pdf.settings import PRIVATE_STORAGE_ROOT
  # Create your models here.
  from blanks.validators import validate_file_extension
  
  class DocFile(models.Model):
      description = models.CharField(max_length=255, blank=True)
      document = models.FileField(upload_to='documents/', validators=[validate_file_extension])
  
      # uploaded_at = models.DateTimeField(auto_now_add=True)
  
      def __str__(self):
          return self.description
  
      def delete(self, *args, **kwargs):
          self.document.delete()
          super().delete(*args, **kwargs)
  
  
  class DocFields(models.Model):
      doc_fields = models.CharField( max_length=50)
  
  
  fs_edited = FileSystemStorage(location=PRIVATE_STORAGE_ROOT)
  
  
  class DocEdited(models.Model):
      edited_description = models.CharField(max_length=250, blank=True)
      document_edited = models.FileField(upload_to='documents_edited/',  storage=fs_edited)
  
      def __str__(self):
          return self.edited_description
  </code></pre>
  
  <p>Here i use EditedDocumentForm class to make a ModelForm, and then i pass it to my views.py  edit_files function , last 6 lines.</p>
  
  <p><strong>forms.py</strong></p>
  
  <pre><code>from django import forms
  from .models import DocFile
  
  from django import forms
  from .models import DocFile , DocEdited
  
  
  class DocumentForm(forms.ModelForm):
      class Meta:
          model = DocFile
          fields = ('description', 'document')
  
  
  class RawProductionForm(forms.Form):
      title_forms = forms.CharField(label='')
  
  
  class VariablesForm(forms.Form):
  
      def __init__(self, *args, **kwargs):
          variables = kwargs.pop('variables')
          super().__init__(*args, **kwargs)
  
          for i, variable in enumerate(variables):
              self.fields['custom_%s' % i] = forms.CharField(label=variable)
  
      def get_input_text(self):
          for name, value in self.cleaned_data.items():
              if name.startswith('custom_'):
                  yield (self.fields[name].label, value)
  
  
  class EditedDocumentForm(forms.ModelForm):
      class Meta:
          model = DocEdited
          fields = ('edited_description','document_edited')
  </code></pre>
  
  <p>look at edit_files function last 6 lines </p>
  
  <p><strong>views.py</strong></p>
  
  <pre><code># -*- coding: utf-8 -*-
  from __future__ import unicode_literals
  from django.views.generic import TemplateView
  from django.shortcuts import render, redirect, get_object_or_404
  from django.core.files.storage import FileSystemStorage
  from django.shortcuts import redirect
  from django.core.files import File
  
  from .forms import DocumentForm, RawProductionForm, VariablesForm, EditedDocumentForm
  from .models import DocFile, DocFields
  
  import os
  import re
  from docx import Document
  
  
  
  class Home(TemplateView):
      template_name = 'home.html'
  
  
  
  
  def file_list(request):
      documents = DocFile.objects.all()
      return render(request, 'file_list.html',{
          'documents': documents
      })
  
  
  def upload_files(request):
      if request.method == 'POST':
          form = DocumentForm(request.POST, request.FILES)
          if form.is_valid():
              form.save()
              return redirect("file_list")
      else:
          form = DocumentForm()
      return render(request, 'upload_files.html',{
          'form': form
      })
  
  
  def docx_words_replace(doc_obj, regex, replace):
  
      for p in doc_obj.paragraphs:
          if regex.search(p.text):
              inline = p.runs
  
  
              for i in range(len(inline)):
                  if regex.search(inline[i].text):
                      text = regex.sub(replace, inline[i].text)
                      inline[i].text = text
  
      for table in doc_obj.tables:
          for row in table.rows:
              for cell in row.cells:
                  docx_words_replace(cell, regex, replace)
  
  def edit_files(request, file_id):
      instance = get_object_or_404(DocFile, id=file_id)
      exact_file = Document(instance.document)
      variables = []
      for paragraph in exact_file.paragraphs:
          match = re.findall(r"\{(.*?)\}", paragraph.text)
          variables.append(match)
      for table in exact_file.tables:
          for row in table.rows:
              for cell in row.cells:
                  match = re.findall(r"\{(.*?)\}", cell.text)
                  variables.append(match)
      exact_file.save('green.pdf')
      temporary_list =  []
      for i in variables:
          for j in i :
              if len(j) &gt; 0:
                  temporary_list.append(j)
      variables = temporary_list
      #  https://stackoverflow.com/questions/9792664/set-changes-element-order
      variables_set = sorted(set(variables), key=variables.index)
  
      inputs_amount = len(variables)
      print(variables)
      inputs_list = []
      my_form = VariablesForm(request.POST, variables=variables_set)
      # Start changing variables
      if request.method == 'POST':
          print(my_form)
          input_texts = my_form.get_input_text()
          for i, input_text in input_texts:
             inputs_list.append(input_text)
  
      print(inputs_list)
      my_dict = dict(zip(variables_set, inputs_list))
      print(my_dict)
      for word , replacement in my_dict.items():
          word_re = re.compile(word)
          docx_words_replace(exact_file, word_re, replacement)
      regex1 = re.compile(r"{")
      regex2 = re.compile(r"}")
      replace = r""
      docx_words_replace(exact_file, regex1, replace)
      docx_words_replace(exact_file, regex2, replace)
  
      if len(inputs_list) != 0:
          files_full_name = inputs_list[0] + '.docx'
          nm = EditedDocumentForm(files_full_name, File(exact_file))
          nm.save()
      return render(request, 'edit_files.html', context={'variables': variables, "form": my_form})
  
  
  def delete_book(request, pk):
      if request.method == 'POST':
          got_to_delete = DocFile.objects.get(pk=pk)
          got_to_delete.delete()
      return redirect('file_list')
  </code></pre>
  
  <p>Here is my Error:</p>
  
  <pre><code>Traceback (most recent call last):
    File "/home/grigor/pdf_3/venv/lib/python3.6/site-packages/django/core/handlers/exception.py", line 34, in inner
      response = get_response(request)
    File "/home/grigor/pdf_3/venv/lib/python3.6/site-packages/django/core/handlers/base.py", line 126, in _get_response
      response = self.process_exception_by_middleware(e, request)
    File "/home/grigor/pdf_3/venv/lib/python3.6/site-packages/django/core/handlers/base.py", line 124, in _get_response
      response = wrapped_callback(request, *callback_args, **callback_kwargs)
    File "/home/grigor/pdf_3/blanks/views.py", line 109, in edit_files
      nm.save()
    File "/home/grigor/pdf_3/venv/lib/python3.6/site-packages/django/forms/models.py", line 449, in save
      if self.errors:
    File "/home/grigor/pdf_3/venv/lib/python3.6/site-packages/django/forms/forms.py", line 180, in errors
      self.full_clean()
    File "/home/grigor/pdf_3/venv/lib/python3.6/site-packages/django/forms/forms.py", line 381, in full_clean
      self._clean_fields()
    File "/home/grigor/pdf_3/venv/lib/python3.6/site-packages/django/forms/forms.py", line 393, in _clean_fields
      value = field.widget.value_from_datadict(self.data, self.files, self.add_prefix(name))
    File "/home/grigor/pdf_3/venv/lib/python3.6/site-packages/django/forms/widgets.py", line 246, in value_from_datadict
      return data.get(name)
  AttributeError: 'str' object has no attribute 'get'
  </code></pre>