Using other file names than models.py for Django models?
<p>When creating a reusable app, should I put all models I define into single file <code>models.py</code> or can I group the models into several files like <code>topic1.py</code>, <code>topic2.py</code>?</p>

<p>Please describe all reasons pro and contra.</p>

<p>The <code>models</code> submodule is special in that it is automatically imported at a specific time during the initialization process. All your models should be imported at this time as well. You can't import them earlier than that, and importing them later may cause errors. </p>

<p>You can define your models in a different module, but you should always import all your models into your <code>models.py</code> or <code>models/__init__.py</code>. E.g.:</p>

<pre><code># models/topic1.py

class Topic1(models.Model):
    ...

# models/__init__.py

from .topic1 import Topic1
</code></pre>

<p>If you import each model into <code>models.py</code> or <code>models/__init__.py</code>, that also allows you to import all the models directly from that file. In the example, that means that you can import <code>Topic1</code> from <code>myapp.models</code>, not just from <code>myapp.models.topic1</code>. This way you can keep your models organized across multiple files without having to remember each model's precise location whenever you need to import them. </p>

python django model