A
A
Artyom Belousov2019-02-12 19:10:38
Django
Artyom Belousov, 2019-02-12 19:10:38

How to store a table with dynamic columns in Django?

There is a task to make it possible to edit the price list, which should be stored in the database. It is a table where the column is the time, the row is the type of service, and the cells store the cost. And here the question is: how best to organize this so that you can edit it from the Django admin panel? At the moment there are 2 main ideas, but each has some significant drawbacks.
One of them: make a JSONField for each service, where the key is the time and the value is the price. But then all the validation will have to be taken over.
Second: to make a "time-price" model. Add a ManyToMany key to it in the service model, but in this case we create an intermediate table that is useless on its own.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question