possible refenrece: <a href="https://stackoverflow.com/questions/12578908/separation-of-business-logic-and-data-access-in-django" rel="nofollow">Separation of business logic and data access in django</a>
In my Django app, I am trying to figure out where to include my business logic. The logic does not fit any models(assume it's a one-page app that doesn't have any models) so I want to add a module that holds the logic. For example,
def calculate(number_one, number_two): return number_one + number_two
Then, I would use the logic like,
def index(request): number = my_logic.calculate(1, 2) #can I do this? return HttpResponse("the number is: %s " % number)
Questions:<ol><li>Where is the right place to put
my_logic.py?</li> <li>Is it conventional?</li> <li>What might be a better way?</li> </ol>
<em>Note: this is how you import your module (if anyone else is trying to figure out how to do it)</em>
from app.your_module import your_moduleAnswer1:
Depends, but if it's a logical unit, then a separate python module would be a good start and you would of course write its own unit tests for it (as opposed to Django's built-in integration tests with TestClient).
If it needs to work within the model, then a property on model would be a better place.