我在Django 1.6应用程序中使用自定义用户模型TrackUser
。当我想删除Adminpanel中的用户时,我收到此错误:
' TrackUser'对象没有属性'替换'
我已经查看了这个question,即使我们的追溯都以../django/utils/html.py
结束,但我找不到解决问题的方法。
模型
class TrackUser(AbstractBaseUser, PermissionsMixin):
#User data
email = models.EmailField(unique=True)
first_name = models.CharField(max_length=75)
last_name = models.CharField(max_length=75)
tel_number = models.BigIntegerField(blank=True, null=True)
address = models.TextField(blank=True, null=True)
#User options
#True for first_name last_name
#False for last_name first_name
full_name_order = models.BooleanField(blank=True, default=True)
#Django necessities
date_joined = models.DateTimeField(default=timezone.now)
is_active = models.BooleanField(default=True)
is_admin = models.BooleanField(default=False)
is_staff = models.BooleanField(default=False)
#Sales fields
percentage_of_sales = models.IntegerField(default=0)
USERNAME_FIELD = 'email'
REQUIRED_FIELDS = ['first_name', 'last_name']
objects = UserManager()
def get_absolute_url(self):
return reverse('user_detail', args=[self.pk])
def get_full_name(self):
if self.full_name_order:
order = (self.first_name, self.last_name)
else:
order = (self.last_name, self.first_name)
return "%s %s" % order
def get_short_name(self):
return self.first_name
def __unicode__(self):
return self.get_full_name()
回溯
Environment:
Request Method: GET
Request URL: http://127.0.0.1:8000/admin/users/trackuser/18/delete/
Django Version: 1.6.5
Python Version: 2.7.6
Installed Applications:
('django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'clients',
'contracts',
'projects',
'products',
'users',
'project_settings',
'south')
Installed Middleware:
('django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware')
Traceback:
File "/Users/jghyllebert/Documents/projects/nuntra/trackapp/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
112. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/Users/jghyllebert/Documents/projects/nuntra/trackapp/lib/python2.7/site-packages/django/contrib/admin/options.py" in wrapper
432. return self.admin_site.admin_view(view)(*args, **kwargs)
File "/Users/jghyllebert/Documents/projects/nuntra/trackapp/lib/python2.7/site-packages/django/utils/decorators.py" in _wrapped_view
99. response = view_func(request, *args, **kwargs)
File "/Users/jghyllebert/Documents/projects/nuntra/trackapp/lib/python2.7/site-packages/django/views/decorators/cache.py" in _wrapped_view_func
52. response = view_func(request, *args, **kwargs)
File "/Users/jghyllebert/Documents/projects/nuntra/trackapp/lib/python2.7/site-packages/django/contrib/admin/sites.py" in inner
198. return view(request, *args, **kwargs)
File "/Users/jghyllebert/Documents/projects/nuntra/trackapp/lib/python2.7/site-packages/django/utils/decorators.py" in _wrapper
29. return bound_func(*args, **kwargs)
File "/Users/jghyllebert/Documents/projects/nuntra/trackapp/lib/python2.7/site-packages/django/utils/decorators.py" in _wrapped_view
99. response = view_func(request, *args, **kwargs)
File "/Users/jghyllebert/Documents/projects/nuntra/trackapp/lib/python2.7/site-packages/django/utils/decorators.py" in bound_func
25. return func(self, *args2, **kwargs2)
File "/Users/jghyllebert/Documents/projects/nuntra/trackapp/lib/python2.7/site-packages/django/db/transaction.py" in inner
371. return func(*args, **kwargs)
File "/Users/jghyllebert/Documents/projects/nuntra/trackapp/lib/python2.7/site-packages/django/contrib/admin/options.py" in delete_view
1457. [obj], opts, request.user, self.admin_site, using)
File "/Users/jghyllebert/Documents/projects/nuntra/trackapp/lib/python2.7/site-packages/django/contrib/admin/util.py" in get_deleted_objects
137. to_delete = collector.nested(format_callback)
File "/Users/jghyllebert/Documents/projects/nuntra/trackapp/lib/python2.7/site-packages/django/contrib/admin/util.py" in nested
191. roots.extend(self._nested(root, seen, format_callback))
File "/Users/jghyllebert/Documents/projects/nuntra/trackapp/lib/python2.7/site-packages/django/contrib/admin/util.py" in _nested
174. children.extend(self._nested(child, seen, format_callback))
File "/Users/jghyllebert/Documents/projects/nuntra/trackapp/lib/python2.7/site-packages/django/contrib/admin/util.py" in _nested
176. ret = [format_callback(obj)]
File "/Users/jghyllebert/Documents/projects/nuntra/trackapp/lib/python2.7/site-packages/django/contrib/admin/util.py" in format_callback
130. obj)
File "/Users/jghyllebert/Documents/projects/nuntra/trackapp/lib/python2.7/site-packages/django/utils/html.py" in format_html
79. args_safe = map(conditional_escape, args)
File "/Users/jghyllebert/Documents/projects/nuntra/trackapp/lib/python2.7/site-packages/django/utils/html.py" in conditional_escape
71. return escape(text)
File "/Users/jghyllebert/Documents/projects/nuntra/trackapp/lib/python2.7/site-packages/django/utils/functional.py" in wrapper
203. return func(*args, **kwargs)
File "/Users/jghyllebert/Documents/projects/nuntra/trackapp/lib/python2.7/site-packages/django/utils/html.py" in escape
39. return mark_safe(force_text(text).replace('&', '&').replace('<', '<').replace('>', '>').replace('"', '"').replace("'", '''))
Exception Type: AttributeError at /admin/users/trackuser/18/delete/
Exception Value: 'TrackUser' object has no attribute 'replace'
答案 0 :(得分:1)
显然,问题仅在TrackUser
链接到另一个模型时出现。
在其中一个模型中,我更改了__unicode__
def __unicode__(self):
return self.user
到
def __unicode__(self):
return self.user.get_full_name()
解决了这个问题