diff options
| author | Jason Pellerin <jpellerin@gmail.com> | 2006-07-19 14:57:42 +0000 |
|---|---|---|
| committer | Jason Pellerin <jpellerin@gmail.com> | 2006-07-19 14:57:42 +0000 |
| commit | 32356827b42cba5adfd197e8bc2cdba440e02a05 (patch) | |
| tree | ea706d134f0822792f1a5079c213fb8ff646a63a | |
| parent | f350bcf05843a854e59f77ca56d2ac77bb4aca4b (diff) | |
[multi-db] Added weakref to model in Options (self._model) and method
Options.get_default_manager().
git-svn-id: http://code.djangoproject.com/svn/django/branches/multiple-db-support@3379 bcc190cf-cafb-0310-a4f2-bffc1f526a37
| -rw-r--r-- | django/db/models/options.py | 10 |
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 '' |
