Query field with reference

27 views
Skip to first unread message

Hélio Miranda

unread,
Oct 8, 2013, 5:23:59 AM10/8/13
to django...@googlegroups.com
Hi
I was trying to make a query in a field that has refencia to another collection, like this:
result = [a.get_json() for a in Player.objects.filter(position__name='DD')]

But it is returning me empty, and I have a player with the position DD
I'm using mongodb as a database.

In my Document is thus:

Does anyone know what I'm doing wrong?

thank you

Leonardo Giordani

unread,
Oct 8, 2013, 5:32:10 AM10/8/13
to django...@googlegroups.com
I do not know MongoDB, so sorry if I get it wrong. I'd say that you have to write

result = [a.get_json() for a in Player.objects.filter(position__position_name='DD')]

since in your attached document you set it this way (line 53).
Try and let me know

Leo


Leonardo Giordani
Author of The Digital Cat
My profile on About.me - My GitHub page - My Coderwall profile


2013/10/8 Hélio Miranda <heli...@gmail.com>

--
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 post to this group, send email to django...@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/47c58f74-484b-4668-9678-7a50fdea842f%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Hélio Miranda

unread,
Oct 8, 2013, 5:36:28 AM10/8/13
to django...@googlegroups.com
Gives error says:
DD is not a valid ObjectId

For the DD not objectId of reference

Hélio Miranda

unread,
Oct 8, 2013, 7:23:52 AM10/8/13
to django...@googlegroups.com
I managed to solve the problem, I did so:
result = [a.get_json() for a in Player.objects.filter(position__in=Position.objects.filter(name=positionpost))]

Thanks for the trouble
Reply all
Reply to author
Forward
0 new messages