Currently all my models are in models.py. Ist becomming very messy.
Can i have the separate file like base_models.py
so that i put my main models there which i don't want to touch
Also same case for views and put in separate folder rather than develop a new app
Yes, it's doable. It's not particularly pretty though:
make models a module, so your directory structure looks like this:
- models
|- __init__.py
|- some_model.py
|- some_other_model.py
|- ...
now, the magic lies in __init__.py
and some little extras in the models. __init__.py
:
from some_model import SomeModel
from some_other_model import SomeOtherModel
__all__ = [
'SomeModel',
'SomeOtherModel',
]
some_model.py:
class SomeModel(models.Model):
class Meta(object):
app_label = 'yourapplabel'
db_table = 'yourapplabel_somemodel'
Everything acjohnson55 said, plus the fact that you need to specify the app_label attribute in each model's Meta class.
A link to an actual example on github: https://github.com/stefanfoulis/django-filer/tree/develop/filer/models
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With