From a537b8e515220986bff97cf5a97138c4eb2e8fa1 Mon Sep 17 00:00:00 2001 From: Adrian Holovaty Date: Fri, 26 May 2006 16:30:42 +0000 Subject: [PATCH] Fixed #1985 -- Got CurrentSiteManager working git-svn-id: http://code.djangoproject.com/svn/django/trunk@2989 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/contrib/sites/managers.py | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/django/contrib/sites/managers.py b/django/contrib/sites/managers.py index 8c1cda5417..d49244f78e 100644 --- a/django/contrib/sites/managers.py +++ b/django/contrib/sites/managers.py @@ -7,20 +7,14 @@ class CurrentSiteManager(models.Manager): def __init__(self, field_name='site'): super(CurrentSiteManager, self).__init__() self.__field_name = field_name - - def contribute_to_class(self, *args, **kwargs): - # This method is overridden purely to check for errors in - # self.field_name. We can't do this in __init__() because of - # how Managers are implemented -- self.model isn't available - # until after contribute_to_class() is called. - super(CurrentSiteManager, self).contribute_to_class(*args, **kwargs) - try: - self.model._meta.get_field(self.__field_name) - except FieldDoesNotExist: - raise ValueError, "%s couldn't find a field named %s in %s." % \ - (self.__class__.__name__, self.__field_name, self.model._meta.object_name) - self.__lookup = self.__field_name + '__id__exact' - del self.__field_name + self.__is_validated = False def get_query_set(self): - return super(SiteLimitManager, self).get_query_set().filter(**{self.__lookup: settings.SITE_ID}) + if not self.__is_validated: + try: + self.model._meta.get_field(self.__field_name) + except FieldDoesNotExist: + raise ValueError, "%s couldn't find a field named %s in %s." % \ + (self.__class__.__name__, self.__field_name, self.model._meta.object_name) + self.__is_validated = True + return super(CurrentSiteManager, self).get_query_set().filter(**{self.__field_name + '__id__exact': settings.SITE_ID})