1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
|
Description: Fix for Django 1.7
With Django 1.7, the call to get_user_model() triggers
django.core.exceptions.AppRegistryNotReady: Models aren't loaded yet.
Author: Victor Bornov
Origin: other, https://bitbucket.org/bornov/django-registration/commits/3c1810ac88aad1569d0a288636803f93fef0b42c
Bug: https://bitbucket.org/ubernostrum/django-registration/pull-request/88/made-call-to-user-lazy-for-django-17-app/diff
Bug-Debian: http://bugs.debian.org/755653
Last-Update: 2014-08-06
diff --git a/registration/models.py b/registration/models.py
--- a/registration/models.py
+++ b/registration/models.py
@@ -4,17 +4,12 @@
import re
from django.conf import settings
-from django.contrib.auth.models import User
from django.db import models
from django.db import transaction
from django.template.loader import render_to_string
from django.utils.translation import ugettext_lazy as _
+from django.contrib.auth import get_user_model
-try:
- from django.contrib.auth import get_user_model
- User = get_user_model()
-except ImportError:
- from django.contrib.auth.models import User
try:
from django.utils.timezone import now as datetime_now
@@ -81,6 +76,8 @@
user. To disable this, pass ``send_email=False``.
"""
+ User = get_user_model()
+
new_user = User.objects.create_user(username, email, password)
new_user.is_active = False
new_user.save()
@@ -151,6 +148,8 @@
be deleted.
"""
+ User = get_user_model()
+
for profile in self.all():
try:
if profile.activation_key_expired():
@@ -179,7 +178,7 @@
"""
ACTIVATED = u"ALREADY_ACTIVATED"
- user = models.ForeignKey(User, unique=True, verbose_name=_('user'))
+ user = models.ForeignKey(settings.AUTH_USER_MODEL, unique=True, verbose_name=_('user'))
activation_key = models.CharField(_('activation key'), max_length=40)
objects = RegistrationManager()
|