Django rext framework join multiple table without nested data

77 views
Skip to first unread message

narendra...@gmail.com

unread,
Feb 1, 2021, 7:17:12 AM2/1/21
to Django users
i have  a two table and want to fetch data based on their relationship using serializer. I'm able to get nested data like

{
'ID':1,
'name':'abc',
'address':[
{
....
}
]


but i want it as in single not as nested
{
.....
}

can any body help me with sample code or reference me a good example so i can understand

Benny M

unread,
Feb 2, 2021, 1:12:25 AM2/2/21
to django...@googlegroups.com
If your using a values_list command, try adding the `flat=True` argument. 
Or you could set the depth on your Meta parameters: https://www.django-rest-framework.org/api-guide/serializers/#specifying-nested-serialization

Benny

On Feb 1, 2021, at 6:17 AM, narendra...@gmail.com <narendra...@gmail.com> wrote:

i have  a two table and want to fetch data based on their relationship using serializer. I'm able to get nested data like
--
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/551a9e41-d743-40d2-bab9-f4e6eb8ea941n%40googlegroups.com.

narendra thapa

unread,
Feb 2, 2021, 10:57:47 AM2/2/21
to django...@googlegroups.com
here are the images of mine code by using the value
_list flat = True and with out it.

i need a flatten json output not a nested one can you help me with that?

Screenshot from 2021-02-02 21-37-23.png
Screenshot from 2021-02-02 21-37-34.png
Screenshot from 2021-02-02 21-37-54.png
Screenshot from 2021-02-02 21-39-12.png
Screenshot from 2021-02-02 21-40-03.png
Screenshot from 2021-02-02 21-40-13.png

Kelechi Divine

unread,
Feb 3, 2021, 9:05:48 AM2/3/21
to django...@googlegroups.com
I'm grateful for the images you've sent to me! It was helpful, and it's a good thing to receive a help at the moment!

Reply all
Reply to author
Forward
0 new messages