Ticket #1821: app_label.diff

File app_label.diff, 1.2 KB (added by mir@…, 9 years ago)

patch

  • django/db/models/base.py

    a b class ModelBase(type): 
    4040        model_module = sys.modules[new_class.__module__]
    4141
    4242        if getattr(new_class._meta, 'app_label', None) is None:
    43             # Figure out the app_label by looking one level up.
    44             # For 'django.contrib.sites.models', this would be 'sites'.
    45             new_class._meta.app_label = model_module.__name__.split('.')[-2]
     43            # Perhaps there's a module attribute?
     44            try:
     45                new_class._meta.app_label = model_module.app_label
     46            except AttributeError:
     47                # Figure out the app_label by looking one level up.
     48                # For 'django.contrib.sites.models', this would be 'sites'.
     49                try:
     50                    new_class._meta.app_label = model_module.__name__.split('.')[-2]
     51                except IndexError:
     52                    raise IndexError, _(
     53"""Interactive model use not directly supported.
     54To circumvent this restriction, add an app_label attribute to each model class or to
     55the model module.""")
    4656
    4757        # Add all attributes to the class.
    4858        for obj_name, obj in attrs.items():
Back to Top