Ticket #8195: django-relative-import-app-label.patch
File django-relative-import-app-label.patch, 1.2 KB (added by , 16 years ago) |
---|
-
django/db/models/base.py
49 49 meta = attr_meta 50 50 base_meta = getattr(new_class, '_meta', None) 51 51 52 kwargs = {} 52 53 if getattr(meta, 'app_label', None) is None: 53 54 # Figure out the app_label by looking one level up. 54 55 # For 'django.contrib.sites.models', this would be 'sites'. 55 56 model_module = sys.modules[new_class.__module__] 56 kwargs = {"app_label": model_module.__name__.split('.')[-2]} 57 else: 58 kwargs = {} 57 try: 58 app_label = model_module.__name__.split('.')[-2] 59 except IndexError: 60 # This was a relative import from the same directory. 61 # Retrieve the full path. 62 from os.path import abspath, split as path_split 63 app_dir = path_split(abspath(model_module.__file__))[0] 64 app_label = path_split(app_dir)[1] 65 66 kwargs["app_label"] = app_label 59 67 60 68 new_class.add_to_class('_meta', Options(meta, **kwargs)) 61 69 if not abstract: