Changeset 7777
- Timestamp:
- 06/28/08 21:35:08 (2 months ago)
- Files:
-
- django/trunk/django/db/models/base.py (modified) (2 diffs)
- django/trunk/django/db/models/options.py (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/trunk/django/db/models/base.py
r7722 r7777 51 51 base_meta = getattr(new_class, '_meta', None) 52 52 53 new_class.add_to_class('_meta', Options(meta)) 53 if getattr(meta, 'app_label', None) is None: 54 # Figure out the app_label by looking one level up. 55 # For 'django.contrib.sites.models', this would be 'sites'. 56 model_module = sys.modules[new_class.__module__] 57 kwargs = {"app_label": model_module.__name__.split('.')[-2]} 58 else: 59 kwargs = {} 60 61 new_class.add_to_class('_meta', Options(meta, **kwargs)) 54 62 if not abstract: 55 63 new_class.add_to_class('DoesNotExist', … … 72 80 old_default_mgr = new_class._default_manager 73 81 new_class._default_manager = None 74 if getattr(new_class._meta, 'app_label', None) is None:75 # Figure out the app_label by looking one level up.76 # For 'django.contrib.sites.models', this would be 'sites'.77 model_module = sys.modules[new_class.__module__]78 new_class._meta.app_label = model_module.__name__.split('.')[-2]79 82 80 83 # Bail out early if we have already created this class. django/trunk/django/db/models/options.py
r7764 r7777 26 26 27 27 class Options(object): 28 def __init__(self, meta ):28 def __init__(self, meta, app_label=None): 29 29 self.local_fields, self.local_many_to_many = [], [] 30 30 self.module_name, self.verbose_name = None, None … … 34 34 self.unique_together = [] 35 35 self.permissions = [] 36 self.object_name, self.app_label = None, None36 self.object_name, self.app_label = None, app_label 37 37 self.get_latest_by = None 38 38 self.order_with_respect_to = None … … 47 47 48 48 def contribute_to_class(self, cls, name): 49 from django.db import connection 50 from django.db.backends.util import truncate_name 51 49 52 cls._meta = self 50 53 self.installed = re.sub('\.models$', '', cls.__module__) in settings.INSTALLED_APPS … … 88 91 del self.meta 89 92 93 # If the db_table wasn't provided, use the app_label + module_name. 94 if not self.db_table: 95 self.db_table = "%s_%s" % (self.app_label, self.module_name) 96 self.db_table = truncate_name(self.db_table, connection.ops.max_name_length()) 97 98 90 99 def _prepare(self, model): 91 from django.db import connection92 from django.db.backends.util import truncate_name93 100 if self.order_with_respect_to: 94 101 self.order_with_respect_to = self.get_field(self.order_with_respect_to) … … 108 115 auto_created=True) 109 116 model.add_to_class('id', auto) 110 111 # If the db_table wasn't provided, use the app_label + module_name.112 if not self.db_table:113 self.db_table = "%s_%s" % (self.app_label, self.module_name)114 self.db_table = truncate_name(self.db_table, connection.ops.max_name_length())115 117 116 118 def add_field(self, field):
