Anonymous
Hi ,I got a problem,i want to return a homemodel obj and its rooms queryset,how to combine them in DRF,thanks
Anonymous
like this,home and room are two model
Anonymous
if i am not override get_object,i am only return home,can not contains room
Rajjix
not sure what you really want there
Rajjix
but u can import your models in your views And use different models in same view with required query sets This is the stuff that django orm makes easy
Rajjix
this might help
Rajjix
https://stackoverflow.com/questions/12187751/django-pass-multiple-models-to-one-template
Anonymous
i want to combining models in one return with Django REST Framework.
Anonymous
in get_object ,i just get a object of model,but i want to get a combining of two models.
Anonymous
i used RetrieveAPIView
Rajjix
https://stackoverflow.com/questions/23700960/serialize-multiple-models-in-a-single-view
Rajjix
def get just means when a user does a get request you pass him data from 2 serializers, which is basically forms in json format and you pass your 2 models to 2 serializers And use those 2 serializers In one view(get request)
Mirco
Maybe I'm not understanding his idea, but why combining two models ? is rooms field a fk of homemodel ?
Rajjix
Maybe I'm not understanding his idea, but why combining two models ? is rooms field a fk of homemodel ?
I really don’t either, but i’m trying to help according to what he asked for
Mirco
yep and it's great 🙏🏻
Anonymous
sorry,my english is not good,please do not mind it
Mirco
yup, but if u see that image, rooms seem to be a fk field so Home model has many rooms
Anonymous
yes
Anonymous
rooms model has fk about Home
Anonymous
i want response two of them in once request
Anonymous
not only home
Mirco
ook so u need nested serializer imho
Mirco
https://pastebin.com/euXQTBzv
Mirco
something like this
Anonymous
yes
Mirco
to get something like this { "title": "Some_Title", "artist": { "id": 2, #or id of the artist. "name": "Artist_name" } }
Mirco
so now try to understand how nested serializers work and use your models
Mirco
Artist and Track are your Home and Room
Anonymous
i knew nest serializers
Mirco
good, so try to implement them like Artist and Track example
Anonymous
i don't know how to do it in view
Anonymous
in APIView
Anonymous
how to overrode the func
Anonymous
i inherit the RetrieveAPIView
Anonymous
it has get_object func
Anonymous
but this func not satisfy my need
Anonymous
Thank you for listening to me for so long.
Mirco
no worries 😁
Anonymous
This is my pool code
Anonymous
http://www.rygh.co/blog/combining-models-django-rest-framework/
Anonymous
Like this
Mirco
https://www.youtube.com/watch?v=QB9gGEwxxM4 this one could help you to understand how to manage views
Anonymous
it's very useful
Anonymous
thank you
Mirco
yw 😁
Anonymous
yw 😁
is Diango has the way which can get data from two tables by its fk, i mean one seach get two tables data
Anonymous
table rooms has fk in home, get home value and its rooms list in one search
Anonymous
get this result
Mirco
Yep From Home model, u can get all of rooms related to it using fk
Mirco
https://docs.djangoproject.com/en/2.1/topics/db/queries/
Anonymous
and i want to get home's value too
Mirco
Yep, you can query all data u need
Mirco
If you have properly set the relationship between models
Mirco
Study Django docs on how to make query and everything's gonna be easier
Anonymous
ok
Anonymous
thx
Mirco
thx
Yw 😀😀
Anonymous
😀
Mirco
Welcome guys 👋
Rajjix
🤔
Dcruz
Wzup? a lot of work? :D
Karthik
Why I can't connect MySQL with django
Karthik
It shows "you need to update visual c++"
Rajjix
Windows visual studio?
Anonymous
Visual c++ redistribution
Karthik
Correct
Karthik
Then do it
Even I update show some error
Karthik
Can I use mangodb
Anonymous
You can
Anonymous
Karthik
I don't know mongo
Karthik
Any resources??
Anonymous
Can I use mangodb
I won't suggest though
Anonymous
Why I can't connect MySQL with django
Try updating driver maybe