SHARE
TWEET

Untitled

a guest Aug 18th, 2018 91 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Redefining class attributes in derived model classes, Django
  2. class CustomUser(User):
  3.   """The inherited User class. Email field are redefined to add the warning
  4.   about uniqueness is required. UserManager as the default manager so that
  5.   the standard methods are available."""
  6.  
  7.   def __init__(self, *args, **kwargs):
  8.       super(CustomUser, self).__init__(*args, **kwargs)
  9.       email = models.EmailField(unique=True)
  10.       email.contribute_to_class(u'email', self)
  11.  
  12.   objects = UserManager()
  13.    
  14. File "/home/i159/Envs/students/lib/python2.6/site-packages/django/core/handlers/base.py"     in get_response
  15.   111.                         response = callback(request, *callback_args,   **callback_kwargs)
  16. File "/home/i159/Envs/students/lib/python2.6/site-packages/django/contrib/admin/options.py" in wrapper
  17.   307.                 return self.admin_site.admin_view(view)(*args, **kwargs)
  18. File "/home/i159/Envs/students/lib/python2.6/site-packages/django/utils/decorators.py" in _wrapped_view
  19.   93.                     response = view_func(request, *args, **kwargs)
  20. File "/home/i159/Envs/students/lib/python2.6/site-packages/django/views/decorators/cache.py" in _wrapped_view_func
  21.   79.         response = view_func(request, *args, **kwargs)
  22. File "/home/i159/Envs/students/lib/python2.6/site-packages/django/contrib/admin/sites.py" in inner
  23.   196.                 return self.login(request)
  24. File "/home/i159/Envs/students/lib/python2.6/site-packages/django/views/decorators/cache.py" in _wrapped_view_func
  25.   79.         response = view_func(request, *args, **kwargs)
  26. File "/home/i159/Envs/students/lib/python2.6/site-packages/django/contrib/admin/sites.py" in login
  27.   331.         return login(request, **defaults)
  28. File "/home/i159/Envs/students/lib/python2.6/site-packages/django/utils/decorators.py" in _wrapped_view
  29.   93.                     response = view_func(request, *args, **kwargs)
  30. File "/home/i159/Envs/students/lib/python2.6/site-packages/django/views/decorators/cache.py" in _wrapped_view_func
  31.   79.         response = view_func(request, *args, **kwargs)
  32. File "/home/i159/Envs/students/lib/python2.6/site-packages/django/contrib/auth/views.py" in login
  33.   35.         if form.is_valid():
  34. File "/home/i159/Envs/students/lib/python2.6/site-packages/django/forms/forms.py" in is_valid
  35.   121.         return self.is_bound and not bool(self.errors)
  36. File "/home/i159/Envs/students/lib/python2.6/site-packages/django/forms/forms.py" in _get_errors
  37.   112.             self.full_clean()
  38. File "/home/i159/Envs/students/lib/python2.6/site-packages/django/forms/forms.py" in full_clean
  39.   268.         self._clean_form()
  40. File "/home/i159/Envs/students/lib/python2.6/site-packages/django/forms/forms.py" in _clean_form
  41.   296.             self.cleaned_data = self.clean()
  42. File "/home/i159/Envs/students/lib/python2.6/site-packages/django/contrib/admin/forms.py" in clean
  43.   26.             self.user_cache = authenticate(username=username, password=password)
  44. File "/home/i159/Envs/students/lib/python2.6/site-packages/django/contrib/auth/__init__.py" in authenticate
  45.   55.             user = backend.authenticate(**credentials)
  46. File "/home/i159/workspace/students/backends.py" in authenticate
  47.   15.         print self.user_class()
  48. File "/home/i159/workspace/students/stdapp/models.py" in __init__
  49.   13.         email.contribute_to_class(u'email', self)
  50. File "/home/i159/Envs/students/lib/python2.6/site-packages/django/db/models/fields/__init__.py" in contribute_to_class
  51.   235.         self.set_attributes_from_name(name)
  52. File "/home/i159/Envs/students/lib/python2.6/site-packages/django/db/models/fields/__init__.py" in set_attributes_from_name
  53.   232.             self.verbose_name = name.replace('_', ' ')
  54.  
  55. Exception Type: AttributeError at /admin/stdapp/customuser/add/
  56. Exception Value: 'CustomUser' object has no attribute 'replace'
  57.    
  58. class CustomUser(User):
  59.     def __init__(self, *args, **kwargs):
  60.         setattr(self._meta.fields[4], 'unique', True)
  61.    
  62. class CustomUser(User):
  63.     def __init__(self, *args, **kwargs):
  64.         self._meta.fields[4].unique=True
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top