Django ORM query with joins

18 views
Skip to first unread message

Anoop Thiparala

unread,
Mar 30, 2020, 7:57:01 AM3/30/20
to Django users
I need help with a django query...I have two models

1) POSTS
==>id
==>details
==>user(foreign key to user table)

2) USER
==>id
==>email
==>name

SQL VERSION: SELECT POSTS.ID, POSTS.DETAILS, USER.NAME FROM POSTS, USER WHERE POSTS.USER == USER.ID;

I require these details in the same queryset...is it possible ? 

Suraj Thapa FC

unread,
Mar 30, 2020, 10:18:26 AM3/30/20
to django...@googlegroups.com
posts.model.values('id', 'details', 'user__name' )

--
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/c59d7b0c-834f-47fe-8162-5e34f42c51f9%40googlegroups.com.

Suraj Thapa FC

unread,
Mar 30, 2020, 10:19:07 AM3/30/20
to django...@googlegroups.com
Sorry its like this...
posts.objects.values('id', 'details', 'user__name' )

Anoop Thiparala

unread,
Mar 31, 2020, 1:31:50 AM3/31/20
to Django users
thanks that worked 


On Monday, March 30, 2020 at 7:49:07 PM UTC+5:30, Suraj Thapa FC wrote:
Sorry its like this...
posts.objects.values('id', 'details', 'user__name' )

On Mon, 30 Mar 2020, 7:46 pm Suraj Thapa FC, <surajt...@gmail.com> wrote:
posts.model.values('id', 'details', 'user__name' )

On Mon, 30 Mar 2020, 5:26 pm Anoop Thiparala, <anthi...@gmail.com> wrote:
I need help with a django query...I have two models

1) POSTS
==>id
==>details
==>user(foreign key to user table)

2) USER
==>id
==>email
==>name

SQL VERSION: SELECT POSTS.ID, POSTS.DETAILS, USER.NAME FROM POSTS, USER WHERE POSTS.USER == USER.ID;

I require these details in the same queryset...is it possible ? 

--
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...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages