Skip to content

Instantly share code, notes, and snippets.

@loic
Created February 11, 2014 10:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save loic/8932470 to your computer and use it in GitHub Desktop.
Save loic/8932470 to your computer and use it in GitHub Desktop.
diff --git a/django/contrib/auth/models.py b/django/contrib/auth/models.py
index 5b89fe8..e8c796a 100644
--- a/django/contrib/auth/models.py
+++ b/django/contrib/auth/models.py
@@ -13,7 +13,6 @@ from django.contrib import auth
from django.contrib.auth.hashers import (
check_password, make_password, is_password_usable)
from django.contrib.auth.signals import user_logged_in
-from django.contrib.contenttypes.models import ContentType
from django.utils.encoding import python_2_unicode_compatible
@@ -29,6 +28,10 @@ user_logged_in.connect(update_last_login)
class PermissionManager(models.Manager):
def get_by_natural_key(self, codename, app_label, model):
+ # Import here since the contenttypes app may not be ready
+ # when this file is imported.
+ from django.contrib.contenttypes.models import ContentType
+
return self.get(
codename=codename,
content_type=ContentType.objects.get_by_natural_key(app_label,
@@ -61,7 +64,7 @@ class Permission(models.Model):
created for each Django model.
"""
name = models.CharField(_('name'), max_length=50)
- content_type = models.ForeignKey(ContentType)
+ content_type = models.ForeignKey('contenttypes.ContentType')
codename = models.CharField(_('codename'), max_length=100)
objects = PermissionManager()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment