1. David Jean Louis
  2. django-admin-tools

Commits

glic3rinu  committed f619e53

Added compatibility with swappable user model (django 1.5)

  • Participants
  • Parent commits b964214
  • Branches default

Comments (0)

Files changed (6)

File admin_tools/dashboard/migrations/0001_initial.py

View file
  • Ignore whitespace
 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()
+
+user_model = '%s.%s' % (User._meta.app_label, User._meta.object_name)
 
 class Migration(SchemaMigration):
 
         # Adding model 'DashboardPreferences'
         db.create_table('admin_tools_dashboard_preferences', (
             ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
-            ('user', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['auth.User'])),
+            ('user', self.gf('django.db.models.fields.related.ForeignKey')(to=orm[user_model])),
             ('data', self.gf('django.db.models.fields.TextField')()),
         ))
         db.send_create_signal('dashboard', ['DashboardPreferences'])
             'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
             'name': ('django.db.models.fields.CharField', [], {'max_length': '50'})
         },
-        'auth.user': {
+        user_model: {
             'Meta': {'object_name': 'User'},
             'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
             'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}),
             'Meta': {'ordering': "('user',)", 'object_name': 'DashboardPreferences', 'db_table': "'admin_tools_dashboard_preferences'"},
             'data': ('django.db.models.fields.TextField', [], {}),
             'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
-            'user': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['auth.User']"})
+            'user': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm[%s]" % user_model})
         }
     }
 

File admin_tools/dashboard/migrations/0002_auto__add_field_dashboardpreferences_dashboard_id.py

View file
  • Ignore whitespace
 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()
+
+user_model = '%s.%s' % (User._meta.app_label, User._meta.object_name)
 
 class Migration(SchemaMigration):
 
             'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
             'name': ('django.db.models.fields.CharField', [], {'max_length': '50'})
         },
-        'auth.user': {
+        user_model: {
             'Meta': {'object_name': 'User'},
             'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
             'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}),
             'dashboard_id': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
             'data': ('django.db.models.fields.TextField', [], {}),
             'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
-            'user': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['auth.User']"})
+            'user': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['%s']" % user_model})
         }
     }
 

File admin_tools/dashboard/migrations/0003_auto__add_unique_dashboardpreferences_dashboard_id_user.py

View file
  • Ignore whitespace
 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()
+
+user_model = '%s.%s' % (User._meta.app_label, User._meta.object_name)
 
 class Migration(SchemaMigration):
 
             'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
             'name': ('django.db.models.fields.CharField', [], {'max_length': '50'})
         },
-        'auth.user': {
+        user_model: {
             'Meta': {'object_name': 'User'},
             'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
             'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}),
             'dashboard_id': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
             'data': ('django.db.models.fields.TextField', [], {}),
             'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
-            'user': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['auth.User']"})
+            'user': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['%s']" % user_model})
         }
     }
 

File admin_tools/dashboard/models.py

View file
  • Ignore whitespace
 This module contains the base classes for the dashboard and dashboard modules.
 """
 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()
 
 class DashboardPreferences(models.Model):
     """
     This model represents the dashboard preferences for a user.
     """
-    user = models.ForeignKey('auth.User')
+    user = models.ForeignKey(User)
     data = models.TextField()
     dashboard_id = models.CharField(max_length=100)
 

File admin_tools/menu/migrations/0001_initial.py

View file
  • Ignore whitespace
 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()
+
+user_model = '%s.%s' % (User._meta.app_label, User._meta.object_name)
 
 class Migration(SchemaMigration):
 
         # Adding model 'Bookmark'
         db.create_table('admin_tools_menu_bookmark', (
             ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
-            ('user', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['auth.User'])),
+            ('user', self.gf('django.db.models.fields.related.ForeignKey')(to=orm[user_model])),
             ('url', self.gf('django.db.models.fields.CharField')(max_length=255)),
             ('title', self.gf('django.db.models.fields.CharField')(max_length=255)),
         ))
             'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
             'title': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
             'url': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
-            'user': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['auth.User']"})
+            'user': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['%s']" % user_model})
         }
     }
 

File admin_tools/menu/models.py

View file
  • Ignore whitespace
 This module contains the base classes for menu and menu items.
 """
 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()
 
 class Bookmark(models.Model):
     """
     This model represents a user created bookmark.
     """
-    user = models.ForeignKey('auth.User')
+    user = models.ForeignKey(User)
     url = models.CharField(max_length=255)
     title = models.CharField(max_length=255)