Sorry for reviving an old topic, but I have a models.py file that is
>15,000 lines and would like to chop it up (PyCharm is groaning under the
weight!).
How would I handle the imports between the chopped-up files in a models
module where the referenced foreign key model is in a different file?
Not a problem at all, Andréas. Gave me a chuckle.
Best,
Boney
On Feb 2, 2021, at 1:45 AM, Andréas Kühne wrote:
Sorry, BENNY M. Apologies.
Regards,
Andréas
Den tis 2 feb. 2021 kl 08:44 skrev Andréas Kühne
mailto:andreas.ku...@hypercode.se>>:
So,
Boney M's assumption here is correct.
Sorry, BENNY M. Apologies.
Regards,
Andréas
Den tis 2 feb. 2021 kl 08:44 skrev Andréas Kühne :
> So,
>
> Boney M's assumption here is correct.
>
> You just need to import all of your models in the __init__.py file using
> relative imports, so for example:
>
> from .car import Car
>
> and so
So,
Boney M's assumption here is correct.
You just need to import all of your models in the __init__.py file using
relative imports, so for example:
from .car import Car
and so on.
This works perfectly and I usually try to split the models in that way as
not to get a models.py that is over
Just a thought, I haven’t tested this: you might be able to trick access to
subdirectories by importing those models in the top-level models/__init__.py -
now that I think about it, you might have to do that with all the models... so
your __init__ file would say something like:
```
from .car
Hello everyone, I have a question about Django and the use of namespaces or
packages to split the models.py file.
I would like to adopt the Java philosophy in which one file corresponds one
class and one db table.
I tried to follow this guide, but it doesn’t work.
6 matches
Mail list logo