0

I have a bunch of REST views and a bunch of data transfers posted from templates that needs to be cleaned. I am wondering where to put all the sanitizing code and processing code should go: views.py or models.py ? Am I missing some secret tricks that I don't know about? (like usage of model.manager) ?

Currently I kept the models clean with object creation and update. Views is nicely organized with strictly REST views. But as the project grows, more and more code, especially handling of data that has accumulated. (views.py file had grown in size to 150lines) Should I put them in another file. If so, is that ok to pass the whole "request" to that file? (along with having to import models and possibly sessions and messages)

theMobDog
  • 1,251
  • 3
  • 13
  • 26

1 Answers1

2

I have implemented my django apps like this:

  • In models.py: just add the definition of the models and some code usefull for the Signals because in my application will work with other models
  • In view.py: here i add the code usefull for manage the form for the frontend and create the json necessary for the API call to external app
  • of course you can split the code in other files and call the functions when needed like fuctions.py or options.py

from .functions import calc

  • External app with Rest Framework: here is the CORE of the application, where i'll call the models, where all the logic is available

This is how i use it, by the way is always better use the view.py for write the code.

Some Tips about The Model View Controller pattern in web applications

Mattia
  • 961
  • 13
  • 25