Answer the question
In order to leave comments, you need to log in
How can I write a model in django so that I can work comfortably with JSON?
I asked the same last question, but I didn’t get a clear answer for me, I’m creating a new one, please don’t swear.
What I need is that:
the site makes a request to the server -> the server looks for certain data and returns JSON -> then JS works on the client with this JSON.
Data is added through the admin panel, for example:
Type - a regular point;
then a certain structure of nested fields so that such an "element" comes out of them:
{
"endPlace": [425, 330],
"icon": "endIcon30",
"startPlace": [
{
"startPoint": [45, 875],
"icon": "startIcon20",
"url": ["[email protected]", "3mcWTjoi2zFE"]
},
{
"startPoint": [51, 670],
"icon": "startIcon20",
"url": ["3mcW212zFE"]
},
{
"startPoint": [51, 670],
"icon": "startIcon20",
"url": ["3mcW212zFE"]
}
]
}
[{
"endPlace": [425, 330],
"icon": "endIcon30",
"startPlace": [
{
"startPoint": [45, 875],
"icon": "startIcon20",
"url": ["[email protected]", "3mcWTjoi2zFE"]
},
{
"startPoint": [51, 670],
"icon": "startIcon20",
"url": ["3mcW212zFE"]
},
{
"startPoint": [51, 670],
"icon": "startIcon20",
"url": ["3mcW212zFE"]
}
]
},
{
"endPlace": [452, 175],
"icon": "endIcon30",
"startPlace": [
{
"startPoint": [936, 845],
"icon": "startIcon20",
"url": ["[email protected]", "[email protected]"]
}
]
},
{
"endPlace": [10, 10],
"icon": "endIcon30",
"startPlace": [
{
"startPoint": [54, 845],
"icon": "startIcon20",
"url": ["_aC5423TjUU", "3mcWT345zFE"]
},
{
"startPoint": [54, 845],
"icon": "startIcon20",
"url": ["_aC5423TjUU", "3mcWT345zFE"]
}
]
}]
Answer the question
In order to leave comments, you need to log in
Well, in your case, everything is quite simple. But you need to use Postgres as a database, since in this case you can use the ArrayField field in Django.
class StartPlace(models.Model):
start_point = models.ArrayField(max_length=10)
icon = models.CharField(max_length=50)
url = models.ArrayField(max_length=10)
class Point(models.Model):
end_place = models.ArrayField(max_length=10)
icon = models.CharField(max_length=50)
start_place = models.ManyToManyField(StartPlace)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question