0

I am attempting to import a model from another app in django.

The following attempt fails:

from venueadmin.models import VenuePermissions

fails how:

Python is not able to located VenuePermissions, i guess circular reference?

from django.apps import apps
suitscity = apps.get_model('suitsandtablesadmin', 'City')

fails how:

raise AppRegistryNotReady("Models aren't loaded yet.") django.core.exceptions.AppRegistryNotReady: Models aren't loaded yet.

so then I tried importing using __import__

suitscity = __import__('suitsandtablesadmin.models')
suitscity = getattr(suitscity, 'City')

and

 suitscity = __import__('suitsandtablesadmin/models')
 suitscity = getattr(suitscity, 'City')

all of which did not work because City is in a different directory suitsandtablesadmin

How can I make any one of these work?

The directory is as follows:

First I am trying to import models into my venue app models folder

suitsandtables 
   suitsandtables
      __init__
      permissions
      settings
      urls
      wsgi
   suitsandtablesadmin
      __init__
      apps
      models   <-- im trying to import a model from here
      serializers
      urls
      views
  suitsusers
      __init__
      apps
      models
      etc.....
  venueadmin
      __init__
      apps
      models
      views
  venues
      __init__
      apps
      models  <-- into here
      views
Daniel Holmes
  • 1,952
  • 2
  • 17
  • 28
  • Please post the direcotry layout of the different apps you are trying to import (your app, `venueadmin`, and `suitsandtablesadmin`) – cowbert Oct 27 '17 at 20:39
  • Your model name from your first attempt `VenuePermissions` does not match `City` from the rest of your attempts. – Alasdair Oct 27 '17 at 20:54
  • @Alasdair thanks Alasdair I was just using random values. That has no base on why the software is failing. –  Oct 27 '17 at 20:56
  • `from myapp.models import MyModel` should work, as long as `myapp` is on the Python path. If your values are made up, it's impossible to give any more help than that. If you've got a circular import, you should try to fix that, rather than using `__import__`. – Alasdair Oct 27 '17 at 20:57
  • when I use a real value `from suitsandtablesadmin.models import City` is the following error: unresolved reference –  Oct 27 '17 at 21:00
  • That sounds like it's not an actual Python error, but from your IDE. As long as the code runs, it doesn't really matter. – Alasdair Oct 27 '17 at 21:05
  • very fair @Alasdair thank you. I am going to test the code and see if we are in business –  Oct 27 '17 at 21:07

0 Answers0