Answer the question
In order to leave comments, you need to log in
How to properly save/load models with dependencies?
emberjs frontend, django+django-rest-framework backend
has an order form. the user there selects values from which value stretches from other tables.
on the server side, of course, the order is presented as a model and the associated tables are models.ForeignKey there, everything is clear with this.
when reading the model from the server (list, retrieve), it seems logical to me to give the model immediately with the inclusion of dependent data (EMBEDDED RECORDS in terms of emberjs). again, there are no problems with this, drf can give it like that.
{
"mainmodel":
{
"id": 1,
"simplefield": "string",
"complexfield" : {
"id": 1,
"name": "somename"
}
}
}
{
"mainmodel":
{
"simplefield": "string2",
"complexfield" : 2
}
}
Answer the question
In order to leave comments, you need to log in
C django-rest-framework did not work, but I see several possible solutions.
Give the models like this:
{
"mainmodel": {
"id": 1,
"simplefield": "string",
"complexfield": 2
},
"complexfield": {
"id": 1,
"name": "somename"
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question