2014-06-10 123 views
0

我在Django 1.6應用程序中使用自定義用戶模型TrackUser。當我想刪除Adminpanel用戶我得到這個錯誤:「模型」對象沒有屬性「替換」

'TrackUser' object has no attribute 'replace'

我已經看了這個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('&', '&amp;').replace('<', '&lt;').replace('>', '&gt;').replace('"', '&quot;').replace("'", '&#39;')) 

Exception Type: AttributeError at /admin/users/trackuser/18/delete/ 
Exception Value: 'TrackUser' object has no attribute 'replace' 
+0

外核層的事我能想到的是,如果有一個'first_name'或者'last_name'是空的,但是你沒有'null'子句。 – karthikr

+0

兩者都被填充。我甚至嘗試更改'__unicode__'來返回電子郵件。但是,同樣的錯誤依然存在 –

回答

1

顯然這個問題時,TrackUser被鏈接到另一個模式纔出現。

在這些模型中的一個,我改變了__unicode__

def __unicode__(self): 
    return self.user 

def __unicode__(self): 
    return self.user.get_full_name() 

這解決了這個問題

相關問題