django-stdimage traceback “The ‘%s’ attribute has no file associated with it”
This traceback happening when you check file to __delete__, but file do not exist on file system
My traceback:
Traceback (most recent call last):
File "/var/www/engine/django/core/handlers/base.py", line 100, in get_response
response = callback(request, *callback_args, **callback_kwargs)
File "/var/www/engine/lib/decorators.py", line 33, in wrapper
output = func(request, *args, **kw)
File "/var/www/engine/participants/views.py", line 44, in participants_regform
if form.is_valid():
File "/var/www/engine/django/forms/forms.py", line 121, in is_valid
return self.is_bound and not bool(self.errors)
File "/var/www/engine/django/forms/forms.py", line 112, in _get_errors
self.full_clean()
File "/var/www/engine/django/forms/forms.py", line 269, in full_clean
self._post_clean()
File "/var/www/engine/django/forms/models.py", line 320, in _post_clean
self.instance = construct_instance(self, self.instance, opts.fields, opts.exclude)
File "/var/www/engine/django/forms/models.py", line 54, in construct_instance
f.save_form_data(instance, cleaned_data[f.name])
File "/var/www/engine/stdimage/fields.py", line 130, in save_form_data
filename = getattr(instance, self.name).path
File "/var/www/engine/django/db/models/fields/files.py", line 64, in _get_path
self._require_file()
File "/var/www/engine/django/db/models/fields/files.py", line 47, in _require_file
raise ValueError("The '%s' attribute has no file associated with it." % self.field.name)
ValueError: The 'photo' attribute has no file associated with it.
Solution:
Change formfield method of class StdImageField in fields.py
diff --git a/engine/stdimage/fields.py b/engine/stdimage/fields.py
index f1d2125..894bbb2 100644
--- a/engine/stdimage/fields.py
+++ b/engine/stdimage/fields.py
@@ -1,4 +1,5 @@
+from django.contrib.admin.widgets import AdminFileWidget
@@ -117,8 +118,10 @@ class StdImageField(ImageField):
'''
Specify form field and widget to be used on the forms
'''
- kwargs['widget'] = DelAdminFileWidget
- kwargs['form_class'] = StdImageFormField
+ #kwargs['widget'] = DelAdminFileWidget
+ if kwargs.get('widget') == AdminFileWidget:
+ kwargs['widget'] = DelAdminFileWidget
+ kwargs['form_class'] = StdImageFormField
return super(StdImageField, self).formfield(**kwargs)
Читайте також:
- Retrieving elements in a specific order in django
- Python + CouchDB
- Ordering related objects in Django
- Django mongoengine cache backend
- django postgresql та SCHEMA для таблиць
- Django admin filter by ranges of ages
- {% TREE %}: Дерева в django-шаблонах
- django excel response
- Django defer, only
- Fix Django 1.4 admin_site ForeignKeyRawIdWidget issue