I have been assigned a challenging task recently, we are designing a website for our customers, and my boss wanted me to create flexible model-creation functions: which means he doesn't want us to "hard code" the models, he told us not to manually define django models but to create them at system runtime.
For example, we have no models related to our business process at first, admin users can define a form's format on our front pages which will be processed by general users later. Then our backend receives the request from front-end and create the form model with fields provided. I found I can create a class by type() function like type(class_name, (models.Model,), attrs), and I did get new class via this function.
But I was wondering how to persist this class in our system? Like saving this new class into my models.py and making migration so that our DB has it as well
vendredi 8 octobre 2021
Is there a way to dynamically create django models(classes)?
Inscription à :
Publier les commentaires (Atom)
Aucun commentaire:
Enregistrer un commentaire