I recently migrated to Python and cannot solve quite simple problem (using Django). A model has JSON field (PostgreSQL), lets say, for example, fruits. When updating an instance, I do it like this:
model.fruits = {"id": 1, "name": "apple"}
model.save()
When editing a model, I would like to add another fruit (append), so the result would have few JSON items, and model.fruits would return value like this:
[
{
"id": 1,
"name": "apple"
},
{
"id": 2,
"name": "banana"
},
{
"id": 3,
"name": "orange"
},
]
I have tried to search for solutions, but it seems like append function for this dictionary overwrites the values, not appends them. What would be a fast way to append items to this JSON field in database? Maybe there is a library for fast work-around?