1

in my venues app model file I am dynamically adding models I need to do work.

from django.apps import apps
state = apps.get_model('suitsandtablesadmin', 'State')
suitscity = apps.get_model('suitsandtablesadmin','City')
suitsneighboorhood = apps.get_model('suitsandtablesadmin', 'Neighborhood')
venuetypes = apps.get_model('suitsandtablesadmin', 'VenueTypes')
venueseatingtypes = apps.get_model('venueadmin', 'SeatingTypes')
costofvenue = apps.get_model('venueadmin', 'VenueCost')
venuecusines = apps.get_model('venueadmin', 'Cusines')
roomprivacy = apps.get_model('venueadmin', 'Roomprivacy')
roomamenities = apps.get_model('suitsandtablesadmin', 'Amenities')

I am doing this because a regular import statement will not work. Python says it can find the model, I am guessing because of circular importing.

I see from this stackoverflow answer that it may be best to import the entire app into the file but how will that help? And is there a better solution? Django 1.7 throws django.core.exceptions.AppRegistryNotReady: Models aren't loaded yet

I also have yet to create any type of migrations is that a cause?

Relevant part of the trace back below

 `File "/home/ri`ckus/Documents/softwareProjects/211hospitality/suitsandtables/backend/suitsandtablesbackend/virtualsuits/suitsandtables/venues/models.py", line 7, in <module>
    state = apps.get_model('suitsandtablesadmin', 'State')
  File "/home/rickus/Documents/softwareProjects/211hospitality/suitsandtables/backend/suitsandtablesbackend/virtualsuits/local/lib/python2.7/site-packages/django/apps/registry.py", line 193, in get_model
    self.check_models_ready()
  File "/home/rickus/Documents/softwareProjects/211hospitality/suitsandtables/backend/suitsandtablesbackend/virtualsuits/local/lib/python2.7/site-packages/django/apps/registry.py", line 132, in check_models_ready
    raise AppRegistryNotReady("Models aren't loaded yet.")
django.core.exceptions.AppRegistryNotReady: Models aren't loaded yet.

i tired doing this but it didn't work either

class Venue(models.Model):

    def __init__(self):
        from django.apps import apps
        suitscity = apps.get_model('suitsandtablesadmin', 'City')
        suitsneighboorhood = apps.get_model('suitsandtablesadmin', 'Neighborhood')
        venueseatingtypes = apps.get_model('venueadmin', 'SeatingTypes')
        costofvenue = apps.get_model('venueadmin', 'VenueCost')
        venuecusines = apps.get_model('venueadmin', 'Cusines')
        roomprivacy = apps.get_model('venueadmin', 'Roomprivacy')
        roomamenities = apps.get_model('suitsandtablesadmin', 'Amenities')



    name = models.CharField(max_length=200)
    # address for display
    streetaddress = models.CharField(max_length=200)
    streetaddress2 = models.CharField(max_length=200, blank=True, null=True)
    city = models.CharField(max_length=200)
    state = models.ForeignKey(state, on_delete=models.CASCADE)
    ....... so on so forth the model continues
  • currently dynamically importing models in individual classes as needed going to see if that works –  Oct 27 '17 at 17:17
  • ok yeah that did nothng. –  Oct 27 '17 at 17:24
  • currently attempting to import via `__import__` but having issue since models are in a different directory. working on it. –  Oct 27 '17 at 19:08
  • Wouldn't it be easier if you solved the circular import problem in the first place? – Mohammad Jafar Mashhadi Oct 30 '17 at 07:41
  • @MJafarMash so it turned out there wasn't a circular import problem. Really my pycharm was just complaining for no reason. I was able to import the normal way. –  Oct 30 '17 at 16:14

0 Answers0