Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

where to put non-model classes in django

Tags:

python

django

I'm now using django 1.6

As I know, if I want to use some model classes (using ORM) I should put them under folder myapp/models.py.

So what if I want to write some non-model classes (not using ORM), i.e. class Util, and only contains some globally used methods, maybe date formatting or something else.

So, where should these code locate? Is there a generally used way to this case?

like image 306
Alfred Huang Avatar asked Jul 20 '14 04:07

Alfred Huang


1 Answers

You can really put them anywhere you like, but I follow the pattern Django itself uses (in admin, cache, etc.) and put such things in a utils.py file. I have one (if necessary) in each app folder, as well as one for the whole project.

like image 113
Kevin Christopher Henry Avatar answered Oct 13 '22 23:10

Kevin Christopher Henry