Ticket #2982: django_models.diff

File django_models.diff, 1.1 KB (added by Bastian Kleineidam <calvin@…>, 18 years ago)
  • django/db/models/base.py

     
    3939        model_module = sys.modules[new_class.__module__]
    4040
    4141        if getattr(new_class._meta, 'app_label', None) is None:
    42             # Figure out the app_label by looking one level up.
     42            # Figure out the app_label by looking one level up above 'models'.
    4343            # For 'django.contrib.sites.models', this would be 'sites'.
    44             new_class._meta.app_label = model_module.__name__.split('.')[-2]
     44            modparts = model_module.__name__.split('.')
     45            # search the first 'models' module name, which
     46            # a) must exist and b) must have a leading module part
     47            assert 'models' in modparts
     48            idx = modparts.index('models')
     49            assert idx > 0
     50            new_class._meta.app_label = modparts[idx-1]
    4551
    4652        # Bail out early if we have already created this class.
    4753        m = get_model(new_class._meta.app_label, name, False)
Back to Top