I am building a chatbot using Django with a MySQL backend.
I have a `ChatSession` model which represents all the useful information to be stored after the end of a chat session .
Here's an example of the content of that field:
```
{
"slots":{
"chal_tech":"What is the Proof",
"nats":["I will fail the course","Nobody likes me"],
"distortion":"Jumping to Conclusions",
"user_name":"parth",
}
}
```
I recently realized that I need to query for some fields in this `slots` dictionary. An example query would be to list out all the `nats` in the last 10 chat sessions.
It seems that reading all the values of the JSONs into dicts and then searching/manipulating them would be inefficient.Therefore I sought to convert this JSON representation into Django ORM models(SQL).
However, while trying to do this I ran into a problem. The "keys" of the `slots` dictionary are probably finite in number, but I don't know exactly how many of them will be required at this point. In any case, it would be a large number (around 50-100).
- Manually writing the model classes for so many attributes in `models.py` seems inefficient and also a bit repetitive (Most of them would simply have a single `JSONfield` or `TextField`). Even with abstract models I would still have to list out classes for all the "keys" in the `models.py` file.
How do I convert this into valid a valid Django ORM/SQL design so that the queries are efficient and the code isn't repetitive ?