diff options
| author | Malcolm Tredinnick <malcolm.tredinnick@gmail.com> | 2008-06-29 02:35:08 +0000 |
|---|---|---|
| committer | Malcolm Tredinnick <malcolm.tredinnick@gmail.com> | 2008-06-29 02:35:08 +0000 |
| commit | d800c0b031aea81ee6f3a7c28ef88c05494e4eea (patch) | |
| tree | c21d09baf30c29e848cf79e31b96d2b35696c0ec /django/db/models/options.py | |
| parent | be6ff148c18f7e60802ea4e1b14bb5a0ee169a95 (diff) | |
Moved the settings of db_table to Options.contribute_to_class().
Some fields need to know the right db_table setting in their own
contribute_to_class(), so waiting until Options._prepare() is a little
inconvenient. This is a deep-internals change. No effect on external code.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@7777 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/db/models/options.py')
| -rw-r--r-- | django/db/models/options.py | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/django/db/models/options.py b/django/db/models/options.py index c2313f221f..e5b30b4746 100644 --- a/django/db/models/options.py +++ b/django/db/models/options.py @@ -25,7 +25,7 @@ DEFAULT_NAMES = ('verbose_name', 'db_table', 'ordering', 'abstract') class Options(object): - def __init__(self, meta): + def __init__(self, meta, app_label=None): self.local_fields, self.local_many_to_many = [], [] self.module_name, self.verbose_name = None, None self.verbose_name_plural = None @@ -33,7 +33,7 @@ class Options(object): self.ordering = [] self.unique_together = [] self.permissions = [] - self.object_name, self.app_label = None, None + self.object_name, self.app_label = None, app_label self.get_latest_by = None self.order_with_respect_to = None self.db_tablespace = settings.DEFAULT_TABLESPACE @@ -46,6 +46,9 @@ class Options(object): self.parents = SortedDict() def contribute_to_class(self, cls, name): + from django.db import connection + from django.db.backends.util import truncate_name + cls._meta = self self.installed = re.sub('\.models$', '', cls.__module__) in settings.INSTALLED_APPS # First, construct the default values for these options. @@ -87,9 +90,13 @@ class Options(object): self.verbose_name_plural = string_concat(self.verbose_name, 's') del self.meta + # If the db_table wasn't provided, use the app_label + module_name. + if not self.db_table: + self.db_table = "%s_%s" % (self.app_label, self.module_name) + self.db_table = truncate_name(self.db_table, connection.ops.max_name_length()) + + def _prepare(self, model): - from django.db import connection - from django.db.backends.util import truncate_name if self.order_with_respect_to: self.order_with_respect_to = self.get_field(self.order_with_respect_to) self.ordering = ('_order',) @@ -108,11 +115,6 @@ class Options(object): auto_created=True) model.add_to_class('id', auto) - # If the db_table wasn't provided, use the app_label + module_name. - if not self.db_table: - self.db_table = "%s_%s" % (self.app_label, self.module_name) - self.db_table = truncate_name(self.db_table, connection.ops.max_name_length()) - 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. |
