Monday, September 15, 2014

Re: Right way to create proxy to User model in Django 1.7

Thank you for your answer.
I corrected my code how you said: MyUser class inherits now directly from auth.models.User and in settings I set AUTH_USER_MODEL = 'myapp.MyUser' and I got another error: 

TypeError: MyUser cannot proxy the swapped model 'myapp.MyUser'.

I found this problem on stackoverflow (http://stackoverflow.com/questions/25144423/django-proxy-user-model-example) with one answer from you and tried to apply you suggestion: inherited from auth.models.AbstractUser instead of auth.models.User, but in this case I receive another error:

AttributeError: type object 'MyUser' has no attribute '_base_manager'

What am I doing wrong?

Thanks,
    Izabella
  

On Saturday, September 13, 2014 7:22:30 PM UTC+3, Daniel Roseman wrote:
On Friday, 12 September 2014 19:54:53 UTC+1, Izabella Gál wrote:
Hi!

Could you, please, help me to find the right way to create proxy to User
model in Django 1.7?

In 'myapp.models.py' I have a MyUser class which should inherit from the
user model specified in settings.AUTH_USER_MODEL:

If I am using the get_user_model() method, I receive the
'django.core.exceptions.AppRegistryNotReady: Models aren't loaded yet.'
exception

class MyUser(get_user_model()):
     class Meta:
         proxy = True

     def my_method(self):
        return 'hello'

And if I replace the get_user_model() method with
settings.AUTH_USER_MODEL, I receive another exception: TypeError: Error
when calling the metaclass bases
     str() takes at most 1 argument (3 given)

In settings.py I have: AUTH_USER_MODEL = 'auth.User'

Thanks in advance!

Izabella

This doesn't make sense. AUTH_USER_MODEL should be set to your MyUser class, which in turn should inherit directly from auth.models.User. 
--
DR.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/564cb5ab-01bc-437e-afa2-4e9df23a5d9b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment