Errors uploading to ImageField on add in django admin

9 views
Skip to first unread message

mortenbagai

unread,
Sep 28, 2005, 10:47:07 AM9/28/05
to Django users
Hello,

I am trying to use ImageField in one of my models, and I am seeing an
issue where I will intermittently get the error listed below when
trying to add a _new_ object in the django admin site. However, the
image actually does get uploaded correctly to the specified location
and the object is indeed created, only the field supposed to contain
the image path is blank. When I go back to edit the object in django
admin, and try uploading the image again, the save works fine and
returns no error.

Any ideas what could be causing this behavior? Obviously not a
permissions issue, since the image is uploaded correctly on both add
and save? From the output, the error seems to be caused by trying to
apply strftime date formatting to a string object, but I thought using
strftime formatting in the upload path was optional?

Thanks for you input!

Morten

=================
Relevant model object:

class Button(meta.Model):
name = meta.CharField('Button Name', maxlength=255, core=True,
db_index=True)
section = meta.ManyToManyField(Section,
filter_interface=meta.HORIZONTAL)
image = meta.ImageField('Button Image', upload_to='page_images',
blank=True)
page = meta.ForeignKey(Page)
createtime = meta.DateField('Created On', auto_now_add=True)
updatetime = meta.DateTimeField('Updated On', auto_now=True)

# metadata
class META:
admin = meta.Admin(
list_display = ('name', 'page'),
)

def __repr__(self):
return self.name

Error output:

There's been an error:

Traceback (most recent call last):

File
"/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-packages/django/core/handlers/base.py",
line 64, in get_response
response = callback(request, **param_dict)

File
"/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-packages/django/views/admin/main.py",
line 778, in add_stage
new_object = manipulator.save(new_data)

File
"/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-packages/django/utils/functional.py",
line 3, in _curried
return args[0](*(args[1:]+moreargs), **dict(kwargs.items() +
morekwargs.items()))

File
"/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-packages/django/core/meta/__init__.py",
line 1482, in manipulator_save
f.save_file(new_data, new_object, change and self.original_object
or None, change, rel=False)

File
"/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-packages/django/core/meta/fields.py",
line 445, in save_file
FileField.save_file(self, new_data, new_object, original_object,
change, rel)

File
"/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-packages/django/core/meta/fields.py",
line 417, in save_file
getattr(new_object, 'save_%s_file' %
self.name)(new_data[upload_field_name]["filename"],
new_data[upload_field_name]["content"])

File
"/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-packages/django/utils/functional.py",
line 3, in _curried
return args[0](*(args[1:]+moreargs), **dict(kwargs.items() +
morekwargs.items()))

File
"/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-packages/django/core/meta/__init__.py",
line 1053, in method_save_file
self.save()

File
"/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-packages/django/utils/functional.py",
line 3, in _curried
return args[0](*(args[1:]+moreargs), **dict(kwargs.items() +
morekwargs.items()))

File
"/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-packages/django/core/meta/__init__.py",
line 790, in method_save
db_values = [f.get_db_prep_save(f.pre_save(getattr(self, f.column),
False)) for f in non_pks]

File
"/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-packages/django/core/meta/fields.py",
line 324, in get_db_prep_save
value = value.strftime('%Y-%m-%d')

AttributeError: 'str' object has no attribute 'strftime'

Reply all
Reply to author
Forward
0 new messages