开发者

Converting Python App into Django

开发者 https://www.devze.com 2023-02-19 14:30 出处:网络
I\'ve got a Python program with about a dozen classes, with several classes possessing instances of other classes, e.g. ObjectA has a list of ObjectB\'s, and a dictionary of (ObjectC, ObjectD) pairs.

I've got a Python program with about a dozen classes, with several classes possessing instances of other classes, e.g. ObjectA has a list of ObjectB's, and a dictionary of (ObjectC, ObjectD) pairs.

My goal is to put the program's functionality on a website.

I've written and tested JSON encode and decode methods for each class. The problem as I see it now is that I need to choose between starting over and writing the models and logic afresh from a database perspective, or simply storing the python objects (encoded as JSON) in the database, and pulling out the开发者_如何学C saved states for changes.

Can someone confirm that these are both valid approaches, and that I'm not missing any other simple options?


Man, what I think you can do is convert the classes you already have made into django model classes. Of course, only the ones that need to be saved to a database. The other classes, as the rest of the code, I recommend you to encapsulate them for use as helper functions. So you don't have to change too much your code and it's going to work fine. ;D

Or, another choice, that can be easier to implement is: put everything in a helper, the classes, the functions and everything else. SO you'll just need to call the functions in your views and define models to save your data into the database.

Your idea of saving the objects as JSON on the database works, but it's ugly. ;) Anyway, if you are in a hurry to deliver the website, anything is valid. Just remember that things made in this way always give us lots of problems in the future.

It hopes that it could be useful! :D

0

精彩评论

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

关注公众号