Re: AttributeError: type object 'User' has no attribute 'objects'

4,077 views
Skip to first unread message
Message has been deleted

Raja Sekar Sambath

unread,
Apr 27, 2020, 8:54:29 AM4/27/20
to django...@googlegroups.com
Try this,

user = User.objects.filter(pk=user_id)

On Mon, 27 Apr 2020 at 17:55, sagar ninave <sagar...@gmail.com> wrote:
i am getting this error

--
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...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/78802542-aae8-4a7f-83e8-8740d9a80513%40googlegroups.com.


--
Thanks & Regards,

Raja Sekar Sambath

sagar ninave

unread,
Apr 27, 2020, 8:55:44 AM4/27/20
to django...@googlegroups.com
i tried but giving same error



--

Kasper Laudrup

unread,
Apr 27, 2020, 9:58:52 AM4/27/20
to django...@googlegroups.com
Hi Sagar,

On 27/04/2020 14.25, sagar ninave wrote:
> i am getting this error
>

It's hard to guess since you don't show where your User class comes
from, but it doesn't seem like its inheriting from the Django model class.

The error message is quite clear. Look at your User model.

Btw. just a hint: please try to "return early". It is quite difficult to
see which else branches are connected to which if statements in the code
following the one throwing the exception.

Kind regards,

Kasper Laudrup

sagar ninave

unread,
Apr 27, 2020, 11:10:21 AM4/27/20
to django...@googlegroups.com
i got answer

i was doing this:
from .models import User
user = User.objects.filter(pk=user_id)

instead i do this:
from .models import MyUser
user =  MyUser.objects.filter(pk=user_id)


error gone




--
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...@googlegroups.com.

georgia...@gmail.com

unread,
Feb 22, 2021, 10:55:57 AM2/22/21
to Django users
Sorry I have the same similar problem, please help, thank you!!
I put the question on stackoverflow, there are questions and reference materials attached.
File "C:\Users\georgiawang\PycharmProjects\libshopapp\store\views.py", line 195, in updateItem** product = Product.objects.get(id=productId) AttributeError: type object 'Product' has no attribute 'objects'**
sagar ninave 在 2020年4月27日 星期一下午11:10:21 [UTC+8] 的信中寫道:
Reply all
Reply to author
Forward
0 new messages