Fixed #4060 -- Databrowse no longer requires admin site to be installed

git-svn-id: http://code.djangoproject.com/svn/django/trunk@5016 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Adrian Holovaty 2007-04-17 07:08:42 +00:00
parent 968a0627d9
commit c64f7f065a
1 changed files with 4 additions and 3 deletions

View File

@ -8,6 +8,8 @@ from django.utils import dateformat
from django.utils.text import capfirst from django.utils.text import capfirst
from django.utils.translation import get_date_formats from django.utils.translation import get_date_formats
EMPTY_VALUE = '(None)'
class EasyModel(object): class EasyModel(object):
def __init__(self, site, model): def __init__(self, site, model):
self.site = site self.site = site
@ -134,14 +136,13 @@ class EasyInstanceField(object):
# This import is deliberately inside the function because it causes # This import is deliberately inside the function because it causes
# some settings to be imported, and we don't want to do that at the # some settings to be imported, and we don't want to do that at the
# module level. # module level.
from django.contrib.admin.views.main import EMPTY_CHANGELIST_VALUE
if self.field.rel: if self.field.rel:
if isinstance(self.field.rel, models.ManyToOneRel): if isinstance(self.field.rel, models.ManyToOneRel):
objs = getattr(self.instance.instance, self.field.name) objs = getattr(self.instance.instance, self.field.name)
elif isinstance(self.field.rel, models.ManyToManyRel): # ManyToManyRel elif isinstance(self.field.rel, models.ManyToManyRel): # ManyToManyRel
return list(getattr(self.instance.instance, self.field.name).all()) return list(getattr(self.instance.instance, self.field.name).all())
elif self.field.choices: elif self.field.choices:
objs = dict(self.field.choices).get(self.raw_value, EMPTY_CHANGELIST_VALUE) objs = dict(self.field.choices).get(self.raw_value, EMPTY_VALUE)
elif isinstance(self.field, models.DateField) or isinstance(self.field, models.TimeField): elif isinstance(self.field, models.DateField) or isinstance(self.field, models.TimeField):
if self.raw_value: if self.raw_value:
date_format, datetime_format, time_format = get_date_formats() date_format, datetime_format, time_format = get_date_formats()
@ -152,7 +153,7 @@ class EasyInstanceField(object):
else: else:
objs = capfirst(dateformat.format(self.raw_value, date_format)) objs = capfirst(dateformat.format(self.raw_value, date_format))
else: else:
objs = EMPTY_CHANGELIST_VALUE objs = EMPTY_VALUE
elif isinstance(self.field, models.BooleanField) or isinstance(self.field, models.NullBooleanField): elif isinstance(self.field, models.BooleanField) or isinstance(self.field, models.NullBooleanField):
objs = {True: 'Yes', False: 'No', None: 'Unknown'}[self.raw_value] objs = {True: 'Yes', False: 'No', None: 'Unknown'}[self.raw_value]
else: else: