Author: jpellerin
Date: 2006-07-19 09:57:42 -0500 (Wed, 19 Jul 2006)
New Revision: 3379

Modified:
   django/branches/multiple-db-support/django/db/models/options.py
Log:
[multi-db] Added weakref to model in Options (self._model) and method 
Options.get_default_manager().


Modified: django/branches/multiple-db-support/django/db/models/options.py
===================================================================
--- django/branches/multiple-db-support/django/db/models/options.py     
2006-07-19 14:39:18 UTC (rev 3378)
+++ django/branches/multiple-db-support/django/db/models/options.py     
2006-07-19 14:57:42 UTC (rev 3379)
@@ -8,6 +8,7 @@
 from django.db.models import Manager
 from bisect import bisect
 import re
+import weakref
 
 # Calculate the verbose_name by converting from InitialCaps to "lowercase with 
spaces".
 get_verbose_name = lambda class_name: 
re.sub('(((?<=[a-z])[A-Z])|([A-Z](?![A-Z]|$)))', ' \\1', 
class_name).lower().strip()
@@ -75,6 +76,9 @@
         if not self.db_table:
             self.db_table = "%s_%s" % (self.app_label, self.module_name)
 
+        # Keep a weakref to my model, for access to managers and such
+        self._model = weakref.ref(model)
+
     def add_field(self, field):
         # Insert the given field in the order in which it was created, using
         # the "creation_counter" attribute of the field.
@@ -100,6 +104,12 @@
                 return f
         raise FieldDoesNotExist, '%s has no field named %r' % 
(self.object_name, name)
 
+    def get_default_manager(self):
+        model = self._model()
+        if model is None:
+            raise ReferenceError("Model no longer available in %s" % self)
+        return model._default_manager
+
     def get_order_sql(self, table_prefix=''):
         "Returns the full 'ORDER BY' clause for this object, according to 
self.ordering."
         if not self.ordering: return ''


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-updates
-~----------~----~----~----~------~----~------~--~---

Reply via email to