Re:Learn web development: Django Web Framework
by voycey on Friday February 10, 2017 @01:40AM
(#13613682)
It has been years since I have used Django - do they still expect everything in the model to go in a single file or can you put each model in it's own file now?
[ Parent
| on HN ]
Re:Learn web development: Django Web Framework
by nicolaslem on Friday February 10, 2017 @02:49AM
(#13613887)
Create a models.py and import there your models from wherever they are. This should do the trick.
Re:Learn web development: Django Web Framework
by anewhnaccount on Friday February 10, 2017 @04:15AM
(#13614209)
Yeah, or another way of splitting up huge models files is to convert models from a module to a package by making a directory models and adding models/__init__.py, models/foo_models.py, models/bar_models.py then doing
from .foo_models import *
from .bar_models import *
in your __init__.py
Re:Learn web development: Django Web Framework
by ageofwant on Friday February 10, 2017 @07:15AM
(#13614835)
Separating models like this is a hint that you may need another app. It has happened numerous times with me now that my models.py gets large and unwieldy, I spends a hour breaking it all out and then I realise my one big God app needs to be 3 smaller ones.