title: Error when getting all model names in django app
body: <p>I am using different dbs inside my django application and while db routing, i am trying to get all models using</p>
  <pre><code>all_models = dict([(name.lower(), cls) for name, cls in app.models.__dict__.items() \
   if isinstance(cls, type)])
  </code></pre>
  <p>While running migrations, i am getting error &quot;name app is not defined&quot;.</p>
  <p>This is my routers.py</p>
  <pre><code>from .models import *
  
  
  
    allmodels = dict([(name.lower(), cls) for name, cls in 
    app.models.__dict__.items() \
   if isinstance(cls, type)])
  
  class MyDBRouter(object):
  
  def db_for_read(self, model, **hints):
      &quot;&quot;&quot; reading model based on params &quot;&quot;&quot;
      return getattr(model.params, 'db')
  
  def db_for_write(self, model, **hints):
      &quot;&quot;&quot; writing model based on params &quot;&quot;&quot;
      return getattr(model.params, 'db')
  
  def allow_migrate(self, db, app_label, model_name = None, **hints):
      &quot;&quot;&quot; migrate to appropriate database per model &quot;&quot;&quot;
      model = allmodels.get(model_name)
      return(model.params.db == db)
  </code></pre>
  <p>Settings.py
  <a href="https://pastebin.com/0XdpqxkJ" rel="nofollow noreferrer">https://pastebin.com/0XdpqxkJ</a></p>