Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #1985 -- Got CurrentSiteManager working

git-svn-id: http://code.djangoproject.com/svn/django/trunk@2989 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit a537b8e515220986bff97cf5a97138c4eb2e8fa1 1 parent 674719b
Adrian Holovaty authored May 26, 2006

Showing 1 changed file with 9 additions and 15 deletions. Show diff stats Hide diff stats

  1. 24  django/contrib/sites/managers.py
24  django/contrib/sites/managers.py
@@ -7,20 +7,14 @@ class CurrentSiteManager(models.Manager):
7 7
     def __init__(self, field_name='site'):
8 8
         super(CurrentSiteManager, self).__init__()
9 9
         self.__field_name = field_name
10  
-
11  
-    def contribute_to_class(self, *args, **kwargs):
12  
-        # This method is overridden purely to check for errors in
13  
-        # self.field_name. We can't do this in __init__() because of
14  
-        # how Managers are implemented -- self.model isn't available
15  
-        # until after contribute_to_class() is called.
16  
-        super(CurrentSiteManager, self).contribute_to_class(*args, **kwargs)
17  
-        try:
18  
-            self.model._meta.get_field(self.__field_name)
19  
-        except FieldDoesNotExist:
20  
-            raise ValueError, "%s couldn't find a field named %s in %s." % \
21  
-                (self.__class__.__name__, self.__field_name, self.model._meta.object_name)
22  
-        self.__lookup = self.__field_name + '__id__exact'
23  
-        del self.__field_name
  10
+        self.__is_validated = False
24 11
 
25 12
     def get_query_set(self):
26  
-        return super(SiteLimitManager, self).get_query_set().filter(**{self.__lookup: settings.SITE_ID})
  13
+        if not self.__is_validated:
  14
+            try:
  15
+                self.model._meta.get_field(self.__field_name)
  16
+            except FieldDoesNotExist:
  17
+                raise ValueError, "%s couldn't find a field named %s in %s." % \
  18
+                    (self.__class__.__name__, self.__field_name, self.model._meta.object_name)
  19
+            self.__is_validated = True
  20
+        return super(CurrentSiteManager, self).get_query_set().filter(**{self.__field_name + '__id__exact': settings.SITE_ID})

0 notes on commit a537b8e

Please sign in to comment.
Something went wrong with that request. Please try again.