I'm using Python 3.5 and Django 1.9.
File "/home/user/virtualenv3.5/lib/python3.5/site-packages/dbsettings/models.py", line 2, in <module>
from django.contrib.sites.models import Site
File "/home/user/virtualenv3.5/lib/python3.5/site-packages/django/contrib/sites/models.py", line 83, in <module>
class Site(models.Model):
File "/home/user/virtualenv3.5/lib/python3.5/site-packages/django/db/models/base.py", line 103, in __new__
"application was loaded. " % (module, name))
RuntimeError: Model class django.contrib.sites.models.Site doesn't declare an explicit app_label and either isn't in an application in INSTALLED_APPS or else was imported before its application was loaded.
The issue is that I do not need sites framework. I tried setting the variable DBSETTINGS_USE_SITES = False
in settings.py
and it did not help (the same error message).
from django.db import models
from dbsettings.settings import USE_SITES, VALUE_LENGTH
if USE_SITES:
from django.contrib.sites.models import Site
class SiteSettingManager(models.Manager):
def get_queryset(self):
sup = super(SiteSettingManager, self)
qs = sup.get_queryset() if hasattr(sup, 'get_queryset') else sup.get_query_set()
return qs.filter(site=Site.objects.get_current())
get_query_set = get_queryset
class Setting(models.Model):
module_name = models.CharField(max_length=255)
class_name = models.CharField(max_length=255, blank=True)
attribute_name = models.CharField(max_length=255)
value = models.CharField(max_length=VALUE_LENGTH, blank=True)
if USE_SITES:
site = models.ForeignKey(Site)
objects = SiteSettingManager()
def save(self, *args, **kwargs):
self.site = Site.objects.get_current()
return super(Setting, self).save(*args, **kwargs)
def __bool__(self):
return self.pk is not None
Please confirm if this change is valid and apply it to the repo.
Thanks for your work.