Commits

Anonymous committed 61c2eff

Updating fields to accomodate custom user model (Django 1.5)

Comments (0)

Files changed (6)

threaded_multihost/fields.py

 from django.db.models import ForeignKey
-from django.contrib.auth.models import User
+from django.contrib.auth import get_user_model
 
 import threadlocals
 
     """
 
     def __init__(self, **kwargs):
-        kwargs.setdefault('to', User)
+        kwargs.setdefault('to', get_user_model())
         kwargs.setdefault('null', True)
         kwargs.setdefault('blank', True)
         ForeignKey.__init__(self, **kwargs)

threaded_multihost/test_app/custom_user/__init__.py

Empty file added.

threaded_multihost/test_app/custom_user/models.py

+from django.contrib.auth.models import AbstractUser
+
+
+class User(AbstractUser):
+    pass

threaded_multihost/test_app/model_tests/models.py

 
 
 class Article(models.Model):
-	user = fields.UserField(related_name='articles')
-	text = models.TextField()
+    user = fields.UserField(related_name='articles')
+    text = models.TextField()
 
-	def  __unicode__(self):
-		return self.text
+    def  __unicode__(self):
+        return self.text
 
 
 class ArticleCreator(models.Model):
-	user = fields.CreatorField(related_name='created_articles')
-	text = models.TextField()
+    user = fields.CreatorField(related_name='created_articles')
+    text = models.TextField()
 
-	def  __unicode__(self):
-		return self.text
+    def  __unicode__(self):
+        return self.text
 
 
 class ArticleEditor(models.Model):
-	user = fields.EditorField(related_name='edited_articles')
-	text = models.TextField()
+    user = fields.EditorField(related_name='edited_articles')
+    text = models.TextField()
 
-	def  __unicode__(self):
-		return self.text
-
+    def  __unicode__(self):
+        return self.text

threaded_multihost/test_app/model_tests/tests.py

 from models import Article, ArticleCreator, ArticleEditor
-from django.contrib.auth.models import User, AnonymousUser
+from django.contrib.auth import get_user_model
+from django.contrib.auth.models import AnonymousUser
 from django.contrib.sites.models import Site
 from threaded_multihost.sites import by_host
 from threaded_multihost.threadlocals import get_current_user, set_current_user
 
 __test__ = {'API_TESTS': """
 
+>>> User = get_user_model()
+
 >>> a = Article(text="Look at me any user")
 >>> a.save()
 >>> a.user is None

threaded_multihost/test_app/settings.py

 ADMINS = (
     # ('Your Name', 'your_email@domain.com'),
 )
+AUTH_USER_MODEL = 'custom_user.User'
 
 MANAGERS = ADMINS
 
     'django.contrib.contenttypes',
     'django.contrib.sessions',
     'django.contrib.sites',
+    'test_app.custom_user',
     'test_app.model_tests',
     'django.contrib.sitemaps',
 )