gpt4 book ai didi

python - Django 'bool' 对象没有属性 '_committed'

转载 作者:太空宇宙 更新时间:2023-11-04 03:50:07 24 4
gpt4 key购买 nike

好吧,我有一个字段类型 FileField,当我尝试删除它的内容时,会返回此错误消息:“bool”对象没有属性“_committed”`上传工作正常,问题仅出现在我尝试删除已发送的文件时。

我的看法:

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) #Error here.
messages.info(request, 'Dados atualizados com sucesso.')
return HttpResponseRedirect('')

编辑:完整的回溯

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

最佳答案

我有同样的错误,原因是我没有在我的表单中设置 enctype, <form enctype="multipart/form-data" method="post" action="/foo/">

关于python - Django 'bool' 对象没有属性 '_committed',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21707698/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com