idlesign / django-siteprefs

Reusable app for Django introducing site preferences system
https://github.com/idlesign/django-siteprefs
BSD 3-Clause "New" or "Revised" License
17 stars 6 forks source link

Doesn't work in Django 2.0 #15

Closed toxa23 closed 6 years ago

toxa23 commented 6 years ago

    from siteprefs.toolbox import patch_locals, register_prefs
  File "/lib/python3.6/site-packages/siteprefs/toolbox.py", line 6, in <module>
    from .models import Preference
  File "/lib/python3.6/site-packages/siteprefs/models.py", line 8, in <module>
    class Preference(models.Model):
  File "/lib/python3.6/site-packages/django/db/models/base.py", line 100, in __new__
    app_config = apps.get_containing_app_config(module)
  File "/lib/python3.6/site-packages/django/apps/registry.py", line 244, in get_containing_app_config
    self.check_apps_ready()
  File "/lib/python3.6/site-packages/django/apps/registry.py", line 127, in check_apps_ready
    raise AppRegistryNotReady("Apps aren't loaded yet.")
django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet.```
idlesign commented 6 years ago

Thank you for the report. 

I'll try to reproduced it this week. Meanwhile a full stacktrace would be helpful.

idlesign commented 6 years ago

Unable to reproduce it with a simple app and quickstart sample (http://django-siteprefs.readthedocs.io/en/latest/quickstart.html). Works as expected.

Do you encounter this exception on start? How do you structure your code?

toxa23 commented 6 years ago

Yes, the exception appears at the very beginning. Please take a look at my settings.py and trace log. I do not deny, maybe this is me doing something wrong. sources.zip

idlesign commented 6 years ago

Some hints:

  1. The basic idea with Django is to use apps. So you need to create settings.py in your app (just as in quickstart) and define settings there.
  2. Boolean value is handled automatically, no need to define field.
  3. To deal with env vars you can use https://github.com/idlesign/envbox or something similar instead of get_env_variable.
idlesign commented 6 years ago

Considered closed. Feel free to reopen if required.

jayvdb commented 4 years ago

I encountered this also, when I try to described preferences in my project/settings.py

Traceback (most recent call last):
  File "/path_to_root/project_wide/settings.py", line 788, in <module>
    from siteprefs.toolbox import preferences
  File "/usr/lib/python3.8/site-packages/siteprefs/toolbox.py", line 11, in <module>
    from .models import Preference
  File "/usr/lib/python3.8/site-packages/siteprefs/models.py", line 6, in <module>
    class Preference(models.Model):
  File "/usr/lib/python3.8/site-packages/django/db/models/base.py", line 107, in __new__
    app_config = apps.get_containing_app_config(module)
  File "/usr/lib/python3.8/site-packages/django/apps/registry.py", line 252, in get_containing_app_config
    self.check_apps_ready()
  File "/usr/lib/python3.8/site-packages/django/apps/registry.py", line 135, in check_apps_ready
    raise AppRegistryNotReady("Apps aren't loaded yet.")
django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet.

@toxa23 's solution works for me https://github.com/BanzaiTokyo/askapp/blob/f1a5aba/siteprefs/toolbox.py#L24 . I'll submit a patch shortly.