On Wed, Feb 20, 2013 at 6:52 AM, Carlos Aguilar <darkange...@gmail.com>wrote:

> I am trying to use the User model outside of django app, but without
> successful.
>
> This is my imports section:
>
> from django.core.management import setup_environ
> from htdjango import settings
> setup_environ(settings)
>
> from django.contrib.auth import get_user_model
>
> I am trying many things but right now I am receiving this error:
>
> Traceback (most recent call last):
>   File "htuser.py", line 539, in <module>
>     user.delete()
>   File "htuser.py", line 99, in delete
>      django_user.objects.delete()
>   File
> "/usr/local/lib/python2.7/dist-packages/django/db/models/manager.py", line
> 232, in __get__
>     raise AttributeError("Manager isn't accessible via %s instances" %
> type.__name__)
> AttributeError: Manager isn't accessible via HTDjangoUser instances
>

You've provided code, but not the code that is actually raising the error
(i.e., htuser.py). However, the error message does tell you exactly what
you're doing wrong -- you're attempting to access a manager, when what you
have is an instance.

Your code will be doing something like this:

> myUser = User.objects.get(username='foo')
> myUser.objects.all()

myUser is an *instance* of User. The ".objects" attribute, representing the
manager, exists for internal reasons, but you can't use it - you're trying
to access a manager on an instance.

> User.objects.all()

*would* be legal -- in this case, you're accessing the manager on the
*class*, not the instance.

Looking at your stack trace, the problem is either on line 539 or line 99
of htuser.py, where you've switched between working with an instance and
working with a model. You'll have to work out for yourself what the fix is.

Yours,
Russ Magee %-)

-- 
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+unsubscr...@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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to