Division of models into different classes?

I have a ton of models. I mean a ton. Is it possible to reorganize these models into a more convenient format using the new Python package?

IE: Current -

myproject/ web/ models.py 

IE: new -

 myproject/ web/ models/ __init__.py events.py registrations.py lessons.py 

... and just import them all into my __init__.py file? I'm kind of new to Python packages, will this essentially act the same as having one models.py file?

+4
source share
1 answer

Yes. This is a little tedious: you will need to reconsider which import to store in each file, etc., but it is definitely possible.

You can also do this in parts by renaming models.py to models/__init__.py (which should not have any effect at all), and then move the material from one module at a time.

+2
source

Source: https://habr.com/ru/post/1379719/


All Articles