possible refenrece: Separation of business logic and data access in django
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,
project/app/my_logic.py
def calculate(number_one, number_two):
return number_one + number_two
Then, I would use the logic like,
project/app/views.py
def index(request):
number = my_logic.calculate(1, 2) #can I do this?
return HttpResponse("the number is: %s " % number)
Questions:
- Where is the right place to put
my_logic.py
? - Is it conventional?
- What might be a better way?
Note: this is how you import your module (if anyone else is trying to figure out how to do it)
project/app/your_module/your_module.py
project/app/your_module/__init__.py
from views.py,
from app.your_module import your_module