aceminer
aceminer

Reputation: 4295

Django design patterns with an engine

I do not have code to discuss this. But more of a conceptual issue.

Say the user would upload some file through a web file page or input some parameters via a page.

Models.py would be storing all the data which I would need to have stored in my database.

My question would be say after the user submits the webpage data via a form. Where should I put my processing logic? In forms.py? If it's a complex process what should be a proper design pattern to put this code?

Upvotes: 0

Views: 288

Answers (2)

deathangel908
deathangel908

Reputation: 9709

  • You don't definitely have to have only views.py. You can specify any other place that handles your request. I guess if you have a lot of different request it would be a good practice to separate them by module. So your view.py won't have 1000 methods or so.

enter image description here

  • You can handle all requests in views.py that would call another module that contains application logic.

enter image description here

Upvotes: 1

AMG
AMG

Reputation: 1646

In Django's typical pattern, you'd handle the request in your app's views.py file. It is simply by convention, you are free to place your code anywhere, but if you are learning and following along with tutorials, views.py is normally where this logic would be expected.

https://docs.djangoproject.com/en/1.10/topics/http/views/

If your model uses FileField, the uploaded files are not stored in the database, rather uploaded files are stored in path specified in your project settings MEDIA_ROOT value. The database FileField stores a relative reference to the file path from MEDIA_ROOT.

https://docs.djangoproject.com/en/1.10/topics/http/file-uploads/

Upvotes: 1

Related Questions