extracting data from three tables

14 views
Skip to first unread message

sum abiut

unread,
Feb 20, 2015, 12:45:19 AM2/20/15
to django...@googlegroups.com
Hi,
I have three models that i want to extract data from them. The models are join using foreign key. i am not sure how to do that in django. Can someone please point me to the right path.

Cheers


James Schneider

unread,
Feb 20, 2015, 4:47:18 AM2/20/15
to django...@googlegroups.com
I would suggest reading this:


and see if that helps out. You can span relationships (in this case, using FK's) using the double-underscore notation. 

I would also check out using select_related() if you would like to keep the number of queries to a minimum. The description of how to use select_related() also includes an example that spans 3 models, which I think is what you are looking for (although you didn't specify whether one model contains the other two FK's, or if you are jumping through one model via an FK to another model FK):


-James


--
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/CAPCf-y7vVA995WHrStKebFOBLQXx9gnu%2B-c0TwaK70uFNA-ZqA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages