我有以下的模型建立:“GETATTR():属性名称必须是字符串”在管理面板错误与ImageField的模型
class UserProfile(models.Model):
"Additional attributes for users."
url = models.URLField()
location = models.CharField(max_length=100)
user = models.ForeignKey(User, unique=True)
avatar = models.ImageField(upload_to='/home/something/www/avatars', height_field=80, width_field=80)
def __unicode__(self):
return "Profile of " + self.user.username
它应该存储有关用户的其他信息,例如头像。
不幸的是,当我尝试通过管理面板来上传图片,它给了我一个错误,是这样的:
getattr(): attribute name must be string
,当我从模型中删除该领域,做一个DB这是不产生重置并重新加载服务器。我想象的原因是这个特定的领域,只是不知道如何。
这是我回溯:
File "/usr/lib/pymodules/python2.6/django/core/handlers/base.py" in get_response
92. response = callback(request, *callback_args, **callback_kwargs)
File "/usr/lib/pymodules/python2.6/django/contrib/admin/options.py" in wrapper
226. return self.admin_site.admin_view(view)(*args, **kwargs)
File "/usr/lib/pymodules/python2.6/django/views/decorators/cache.py" in _wrapped_view_func
44. response = view_func(request, *args, **kwargs)
File "/usr/lib/pymodules/python2.6/django/contrib/admin/sites.py" in inner
186. return view(request, *args, **kwargs)
File "/usr/lib/pymodules/python2.6/django/db/transaction.py" in _commit_on_success
240. res = func(*args, **kw)
File "/usr/lib/pymodules/python2.6/django/contrib/admin/options.py" in add_view
718. new_object = self.save_form(request, form, change=False)
File "/usr/lib/pymodules/python2.6/django/contrib/admin/options.py" in save_form
551. return form.save(commit=False)
File "/usr/lib/pymodules/python2.6/django/forms/models.py" in save
407. fail_message, commit, exclude=self._meta.exclude)
File "/usr/lib/pymodules/python2.6/django/forms/models.py" in save_instance
65. f.save_form_data(instance, cleaned_data[f.name])
File "/usr/lib/pymodules/python2.6/django/db/models/fields/files.py" in save_form_data
283. setattr(instance, self.name, data)
File "/usr/lib/pymodules/python2.6/django/db/models/fields/files.py" in __set__
316. self.field.update_dimension_fields(instance, force=True)
File "/usr/lib/pymodules/python2.6/django/db/models/fields/files.py" in update_dimension_fields
368. (self.width_field and not getattr(instance, self.width_field))
Exception Type: TypeError at /admin/proj/userprofile/add/
Exception Value: getattr(): attribute name must be string
投了你,谢谢。 – cwj 2009-11-05 21:37:19