Commits

Aram Dulyan committed a94abc1

Alternate way of determining the custom User model, which doesn't cause circular imports when a custom User model is actually used.

Comments (0)

Files changed (6)

admin_tools/dashboard/migrations/0001_initial.py

 from south.db import db
 from south.v2 import SchemaMigration
 from django.db import models
-try:
-    from django.contrib.auth import get_user_model
-except ImportError: # django < 1.5
-    from django.contrib.auth.models import User
-else:
-    User = get_user_model()
+from django.conf import settings
 
-user_model = '%s.%s' % (User._meta.app_label, User._meta.object_name)
+user_model = getattr(settings, 'AUTH_USER_MODEL', 'auth.User')
+
 
 class Migration(SchemaMigration):
 

admin_tools/dashboard/migrations/0002_auto__add_field_dashboardpreferences_dashboard_id.py

 from south.db import db
 from south.v2 import SchemaMigration
 from django.db import models
-try:
-    from django.contrib.auth import get_user_model
-except ImportError: # django < 1.5
-    from django.contrib.auth.models import User
-else:
-    User = get_user_model()
+from django.conf import settings
 
-user_model = '%s.%s' % (User._meta.app_label, User._meta.object_name)
+user_model = getattr(settings, 'AUTH_USER_MODEL', 'auth.User')
+
 
 class Migration(SchemaMigration):
 

admin_tools/dashboard/migrations/0003_auto__add_unique_dashboardpreferences_dashboard_id_user.py

 from south.db import db
 from south.v2 import SchemaMigration
 from django.db import models
-try:
-    from django.contrib.auth import get_user_model
-except ImportError: # django < 1.5
-    from django.contrib.auth.models import User
-else:
-    User = get_user_model()
+from django.conf import settings
 
-user_model = '%s.%s' % (User._meta.app_label, User._meta.object_name)
+user_model = getattr(settings, 'AUTH_USER_MODEL', 'auth.User')
+
 
 class Migration(SchemaMigration):
 

admin_tools/dashboard/models.py

 """
 This module contains the base classes for the dashboard and dashboard modules.
 """
+from django.conf import settings
 from django.db import models
-try:
-    from django.contrib.auth import get_user_model
-except ImportError: # django < 1.5
-    from django.contrib.auth.models import User
-else:
-    User = get_user_model()
+
+user_model = getattr(settings, 'AUTH_USER_MODEL', 'auth.User')
+
 
 class DashboardPreferences(models.Model):
     """
     This model represents the dashboard preferences for a user.
     """
-    user = models.ForeignKey(User)
+    user = models.ForeignKey(user_model)
     data = models.TextField()
     dashboard_id = models.CharField(max_length=100)
 

admin_tools/menu/migrations/0001_initial.py

 from south.db import db
 from south.v2 import SchemaMigration
 from django.db import models
-try:
-    from django.contrib.auth import get_user_model
-except ImportError: # django < 1.5
-    from django.contrib.auth.models import User
-else:
-    User = get_user_model()
+from django.conf import settings
 
-user_model = '%s.%s' % (User._meta.app_label, User._meta.object_name)
+user_model = getattr(settings, 'AUTH_USER_MODEL', 'auth.User')
+
 
 class Migration(SchemaMigration):
 

admin_tools/menu/models.py

 """
 This module contains the base classes for menu and menu items.
 """
+from django.conf import settings
 from django.db import models
-try:
-    from django.contrib.auth import get_user_model
-except ImportError: # django < 1.5
-    from django.contrib.auth.models import User
-else:
-    User = get_user_model()
+
+user_model = getattr(settings, 'AUTH_USER_MODEL', 'auth.User')
+
 
 class Bookmark(models.Model):
     """
     This model represents a user created bookmark.
     """
-    user = models.ForeignKey(User)
+    user = models.ForeignKey(user_model)
     url = models.CharField(max_length=255)
     title = models.CharField(max_length=255)
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.