summaryrefslogtreecommitdiff
path: root/django/db/models/options.py
diff options
context:
space:
mode:
Diffstat (limited to 'django/db/models/options.py')
-rw-r--r--django/db/models/options.py10
1 files changed, 10 insertions, 0 deletions
diff --git a/django/db/models/options.py b/django/db/models/options.py
index a79b48371c..0e8799db57 100644
--- a/django/db/models/options.py
+++ b/django/db/models/options.py
@@ -8,6 +8,7 @@ from django.db.models.query import orderlist2sql
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 @@ class Options(object):
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 @@ class Options(object):
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 ''