开发者

Django: Chicken or Egg question

I am building an application that will send an API call and save the resulting information after processing the information in a APIRecord(models.Model) class.

1) Should I build a separate class in such a way that the class does the API call, processes the information (including checking against business rules) and then creates an instance of my APIRecord() class?

Or

2) Should I build a separate class with the appropriate methods for processing, and calling the API, and then in my model, override the APIRecord.save() method to call the separate class's API methods and then save the results?

Or

3) Should I build my model class with the appropriate methods for calling the API and processing the response (including checking for certain values and other business rules)?

I tried # 2 an开发者_JAVA技巧d ran into problems with flexibility (but am still open to suggestion). I'm leaning towards # 1, but I'm not sure of all the negatives yet?


it is design decision. it depends to your design and programming interests. i used the combination of three methods you said. if i need to some informations that can be build from other fields then i will create an internal function in model class. if i need other records of database to do something i will create an function outside of model class. and other unusual needs will be computed everywhere i need them.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜