Ticket #13903: patch.diff
File patch.diff, 1.7 KB (added by , 14 years ago) |
---|
-
django/db/models/base.py
43 43 base_meta = getattr(new_class, '_meta', None) 44 44 45 45 if getattr(meta, 'app_label', None) is None: 46 # Figure out the app_label by looking one level up. 47 # For 'django.contrib.sites.models', this would be 'sites'. 46 # Figure out the app_label 47 # For 'django.contrib.sites.models', this would be 'sites'; 48 # For 'something', this would ve 'something'. 48 49 model_module = sys.modules[new_class.__module__] 49 kwargs = {"app_label": model_module.__name__.split('.')[-2]} 50 namespace = model_module.__name__.split('.') 51 if len(namespace) > 1: 52 app_label = namespace[-2] 53 else: 54 app_label = namespace[0] 55 kwargs = {"app_label": app_label} 50 56 else: 51 57 kwargs = {} 52 58 -
tests/modeltests/model_package/tests.py
77 77 >>> Article._meta.get_field('publications').m2m_reverse_name() 78 78 'publication_id' 79 79 80 # Tests app_label if model is defined in strange places 81 >>> import sys 82 >>> old_name = sys.modules[__name__].__name__ 83 >>> sys.modules[__name__].__name__ = 'top_level' 84 >>> class TopLevel(models.Model): pass 85 >>> TopLevel._meta.app_label 86 'top_level' 87 88 >>> sys.modules[__name__].__name__ = old_name 89 80 90 """} 81 91 82 92