开发者

How to automate creating models in django?

开发者 https://www.devze.com 2023-03-10 07:33 出处:网络
My models are generated from the shapefiles by using ogrinspect . But , after the creation of the model , lets say the user want to add an additional attribute . For this , the new attribute should be

My models are generated from the shapefiles by using ogrinspect . But , after the creation of the model , lets say the user want to add an additional attribute . For this , the new attribute should be reflected in two tables . One should contain the name of the attribute , the other the attribute as a column . The name of the attribute doesnt need a change in model , and c开发者_如何学运维an be easily taken care of . But how to add an attribute to a table which was generated automatically ?


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

If you expect the models in your application to be changing a lot - particularly if it can be changed by end-users, you are probably thinking about it the wrong way. You may need to think about re-designing your information schema so it is more flexible!

If you have any more information about what you are trying to achieve, we may be able to offer suggestions!


Use post_save signal. (docs)

0

精彩评论

暂无评论...
验证码 换一张
取 消