title: How to split model declaration in files with Peewee
body: <p>I would like to split my code that define the models in my database in differents Python files, to have my project more structured.</p>
  
  <p>Sadly, I end up with an inclusion loop, and an error show up cause some stuff is not initialized when it should be.</p>
  
  <p>I have done something like this for now (simplified) :</p>
  
  <pre class="lang-py prettyprint-override"><code>
  # In file file_database.py
  
  import peewee as pw
  
  from tables import Table1, Table2, Table3
  
  DATABASE_PATH = ...
  MY_DB = pw.SqliteDatabase(DATABASE_PATH)
  
  def make_tables():
      """Make the tables in the database if they don't already exist."""
      MY_DB.create_tables([Table1, Table2, Table3]) # Problem happens here
  
  # Create the database file if it doesn't already exist
  if not DATABASE_PATH.exists():
      LOGGER.info("The database doesn't exists. Creating it...")
      make_tables()
  
  # In file tables.py
  
  import peewee as pw
  
  from file_database import MY_DB
  
  class BaseModel(pw.Model):
      class Meta:
          database = MY_DB
  
  class Table1(BaseModel):
      name = ...
  
  class Table2(BaseModel):
      name = ...
  
  class Table3(BaseModel):
      name = ...
  </code></pre>
  
  <p>And I have a exception like :
  <code>ImportError: cannot import name 'Table1'</code>
  which seems to be logic as the function <code>makeTables</code> needs to import the tables from <code>tables.py</code> first.
  But this one needs the database from <code>file_database.py</code>.</p>
  
  <p>So I'm stuck here.
  I also tried to place the <code>from tables import Table1, Table2, Table3</code> inside the <code>makeTables</code> function to try to do some kind of lazy loading, but without success.</p>
  
  <p>Is there an helping hand out there ? Thanks.</p>