I am creating REST API's.
django==3.2.2
djangorestframework==3.12.4
psycopg2==2.8.6
I am new to Django, python. I looking for a way to use the JSON field in the Django model. My model looks like below -
class Question(BaseModel):
.... other code...
attributes = models.JSONField()
Now I want the attributes to be a JSON, like below
{
"index": 0,
"guid": "95161b18-75a8-46bf-bb1f-6d1e16e3d60b",
"isActive": false,
"latitude": -25.191983,
"longitude": -123.930584,
"tags": [
"esse",
"sunt",
"quis"
],
"friends": [
{
"id": 0,
"name": "Contreras Weeks"
},
{
"id": 1,
"name": "Dawn Lott"
}
]
}
Should I create a new model, but creating a new model will make it add to migrations which I do not want.
- How to create a model for the above?
- How can I use the default validation provided by Django ORM on it?