How to automate the creation of models in django?

My models are created from shapefiles using ogrinspect. But, after creating the model, let's say the user wants to add an additional attribute. To do this, the new attribute must be reflected in two tables. You must specify an attribute name, the other as a column. The attribute name does not need to change the model, and it can be easily taken care of. But how to add an attribute to a table that was automatically generated?

+3
source share
2 answers

You can use South to manage change changes in your models. Whenever a model is changed, you can run schemamigration --auto <appname>to create a migration and then migrate <appname>to apply it. This will create tables in your model.

If you expect models in your application to change a lot, especially if they can be changed by end users, you are probably thinking about it wrong. You may need to consider re-designing your information scheme to make it more flexible!

If you have more detailed information about what you are trying to achieve, we can offer suggestions!

+2
source

Use a signal post_save. ( docs )

0
source

All Articles