Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LazyUser get_user_class returns string, not class #38

Open
aschriner opened this issue Apr 27, 2014 · 1 comment
Open

LazyUser get_user_class returns string, not class #38

aschriner opened this issue Apr 27, 2014 · 1 comment

Comments

@aschriner
Copy link

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.

@aschriner
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant