ACESS FOREIGN KEY TABLE

17 views
Skip to first unread message

Soumen Khatua

unread,
Mar 12, 2020, 4:55:56 AM3/12/20
to django...@googlegroups.com
Hi Folks,
My profile model is Foreignkey in another model called Skill,Now I fetch all the data of this user from Profile table(model) and store it into a variable called user_profile and now my query is I want to fetch the data of the Skill table(model) by using this variable.How I can do that??

Thank you in advance


Regards,
Soumen

Sunday Iyanu Ajayi

unread,
Mar 14, 2020, 4:54:15 PM3/14/20
to django...@googlegroups.com
How are you querying it? Is it from python script or database query?
If it is a SQL database like postgres, you can join the two tables using the "JOIN" syntax . You join the two tables using their ids

SELECT *
FROM profile p
JOIN skill s ON s.user_profile = p.id

NB: You can customize the SELECT to select specific columns from both tables


Virus-free. www.avast.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 view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAPUw6WbQEQGF1U4UVKT4kJBWCsHJ%2BC5JX-_u-UpQREcMCuV6XA%40mail.gmail.com.
Reply all
Reply to author
Forward
0 new messages