django-lazysignup
django-lazysignup copied to clipboard
LazyUser `get_user_class` returns string, not class
The call to rel.to
on LazyUser user field returns a string "auth.User", not the class.
@classmethod
def get_user_class(cls):
return cls._meta.get_field('user').rel.to
This results in AttributeError: 'str' object has no attribute '_meta'
when I try to do LazyUser.objects.create_lazy_user()
replacing the definition of the User foriegnkey
user = models.ForeignKey(
getattr(settings, 'LAZYSIGNUP_USER_MODEL', 'auth.User'),
unique=True)
with
user = models.ForeignKey(
user_model,
unique=True)
where
USER_MODEL = getattr(settings, 'LAZYSIGNUP_USER_MODEL', 'auth.User')
user_model = models.get_model(*USER_MODEL.split("."))
fixes the issue for me. I'm wondering why this is happening at all though?? Usually rel.to does in fact return a class.
This is strange - if I import my own app's model (which has an FK to user using the string reference method) BEFORE importing LazyUser, then rel.to returns a class.
>>> from lazysignup.models import LazyUser
>>> LazyUser.user.field.rel.to
'auth.User'
>>> from supporters.models import Profile
>>> Profile.user.field.rel.to
<class 'django.contrib.auth.models.User'>
>>> LazyUser.user.field.rel.to
<class 'django.contrib.auth.models.User'>
and the only thing that supporters.models is importing is from django.db import models