Django 'bool' object has no attribute '_committed'

6

I have a field of type FileField and when I try to delete the contents of it, it returns me this error message: ´bool' object has no attribute '_committed'

To upload normally, the problem is only when I try to remove the uploaded file.

try:
    profile = request.user.get_profile()
    company = profile.company
except ObjectDoesNotExist:
    raise Http404    


if request.method == 'POST':
   data = request.POST
   profile_form = EditUserProfileForm(data=data)
   company_form = EditCompanyForm(data=data, files=request.FILES)

  if profile_form.is_valid() and company_form.is_valid():
     profile_form.save(profile)
     company_form.save(company)
     messages.info(request, 'Dados atualizados com sucesso.')
     return HttpResponseRedirect('')
 else:
    profile_form.save(profile)
    company_form.save(company)  #Erro Ao tentar salvar o company.
    messages.info(request, 'Dados atualizados com sucesso.')
    return HttpResponseRedirect('')

Edit: the complete traceback

Traceback:
    File "/home/vanderson/.virtualenvs/cargobr/local/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
      111.response = callback(request, *callback_args, **callback_kwargs)
    File "/home/vanderson/.virtualenvs/cargobr/local/lib/python2.7/site-packages/django/contrib/auth/decorators.py" in _wrapped_view
      23.                 return view_func(request, *args, **kwargs)
    File "/home/vanderson/Sites/cargo-br/cargobr/../cargobr/apps/accounts/views.py" in edit
      407.                     company_form.save(company)
    File "/home/vanderson/Sites/cargo-br/cargobr/../cargobr/apps/accounts/forms.py" in save
      147.         company.save()
    File "/home/vanderson/.virtualenvs/cargobr/local/lib/python2.7/site-packages/django/db/models/base.py" in save
      460.         self.save_base(using=using, force_insert=force_insert, force_update=force_update)
    File "/home/vanderson/.virtualenvs/cargobr/local/lib/python2.7/site-packages/django/db/models/base.py" in save_base
      484.             signals.pre_save.send(sender=origin, instance=self, raw=raw, using=using)
    File "/home/vanderson/.virtualenvs/cargobr/local/lib/python2.7/site-packages/django/dispatch/dispatcher.py" in send
      172.             response = receiver(signal=self, sender=sender, **named)
    File "/home/vanderson/.virtualenvs/cargobr/local/lib/python2.7/site-packages/easy_thumbnails/signal_handlers.py" in find_uncommitted_filefields
      20.             if not getattr(instance, field.name)._committed:

    Exception Type: AttributeError at /editar-cadastro/
    Exception Value: 'bool' object has no attribute '_committed'

EditCompanyForm:

class EditCompanyForm(CompanyForm):

    class Meta:
        model = accounts.models.Company
        exclude = ('verified', 'rating')


    def save(self, company):
        company.insurance_policy = self.cleaned_data['insurance_policy']
        company.save()
        return company
    
asked by anonymous 11.02.2014 / 17:35

1 answer

2

The problem seems to be that you have overridden the% method of% of the Form without calling the original save() . Try changing this code:

def save(self, company):
    company = super(EditCompanyForm, self).save(
        commit=False)
    company.insurance_policy = self.cleaned_data['insurance_policy']
    company.save(commit=True)
    return company
    
19.02.2014 / 21:53