Skip to content

Commit

Permalink
Added MONGOADMIN_CHECK_CONTENTTYPE setting switch of the mongoadmin c…
Browse files Browse the repository at this point in the history
…ontenttypes
  • Loading branch information
jschrewe committed Sep 13, 2013
1 parent 9c91230 commit d5633d2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
24 changes: 14 additions & 10 deletions mongoadmin/contenttypes/utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import sys

from django.conf import settings
from django.core.exceptions import ImproperlyConfigured
from django.contrib.contenttypes.models import ContentType
from django.db.models import get_model
Expand All @@ -11,16 +12,19 @@
# object from it, we simply export Django's stuff and are done.
# Otherwise we roll our own (mostly) compatible version
# using mongoengine.
try:
ContentType.objects.all()[0]
HAS_RELATIONAL_DB = True
except ImproperlyConfigured:
# This assumes you use django.db.backends.dummy for now.
HAS_RELATIONAL_DB = False
except (DatabaseError, IndexError):
# Chances are high that a db has been configured if
# we get that exception. So we assume that a we have
# a relational db
if getattr(settings, 'MONGOADMIN_CHECK_CONTENTTYPE', True):
try:
ContentType.objects.all()[0]
HAS_RELATIONAL_DB = True
except ImproperlyConfigured:
# This assumes you use django.db.backends.dummy for now.
HAS_RELATIONAL_DB = False
except (DatabaseError, IndexError):
# Chances are high that a db has been configured if
# we get that exception. So we assume that a we have
# a relational db
HAS_RELATIONAL_DB = True
else:
HAS_RELATIONAL_DB = True

def get_model_or_document(app_label, model):
Expand Down
2 changes: 0 additions & 2 deletions mongoadmin/validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,6 @@ def validate_base(cls, model):
check_isseq(cls, 'raw_id_fields', cls.raw_id_fields)
for idx, field in enumerate(cls.raw_id_fields):
f = get_field(cls, model, opts, 'raw_id_fields', field)
print f
print
if not (isinstance(f, ReferenceField) or \
(isinstance(f, ListField) and isinstance(f.field, ReferenceField))):
raise ImproperlyConfigured("'%s.raw_id_fields[%d]', '%s' must "
Expand Down

0 comments on commit d5633d2

Please sign in to comment.