T
T
TechnoPro2022-04-17 00:38:27
Django
TechnoPro, 2022-04-17 00:38:27

Is it possible to create model fields via a form in Django?

The customer wants the ability to add / change / delete arbitrary fields in the user card, the person who will be doing this, presumably without programming knowledge. I'm trying to find a way to change the DB structure through forms.
Does anyone know a possible way to solve this problem? Kick in the right direction)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey Gornostaev, 2022-04-17
@sergey-gornostaev

If PostgreSQL is used, then HStore. If not, then EAV.

J
Jack444, 2022-04-17
@Jack444

Create an additional table, store the location of your models in it, namely on which line the last field ends. When a change request comes through the form, then change the file models and admin, then shift all other models by the number of added or reduced lines, at the end, through the OS, perform migrations and reload django.
This is such a crutch solution, but it will work.
The best option is to use JsonField, but when deleting and changing a field, you will need to take a selection of all records and delete or add a field in each. Or make a separate connection to psycopg and a direct SQL query to delete/update everything.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question