Ticket #8108: 8108.diff

File 8108.diff, 1.6 KB (added by evan_schulz, 16 years ago)
  • django/db/models/base.py

     
    1111import django.db.models.manipulators    # Imported to register signal handler.
    1212import django.db.models.manager         # Ditto.
    1313from django.core import validators
    14 from django.core.exceptions import ObjectDoesNotExist, MultipleObjectsReturned, FieldError
     14from django.core.exceptions import ObjectDoesNotExist, MultipleObjectsReturned, FieldError, ImproperlyConfigured
    1515from django.db.models.fields import AutoField, ImageField
    1616from django.db.models.fields.related import OneToOneRel, ManyToOneRel, OneToOneField
    1717from django.db.models.query import delete_objects, Q, CollectedObjects
     
    5353            # Figure out the app_label by looking one level up.
    5454            # For 'django.contrib.sites.models', this would be 'sites'.
    5555            model_module = sys.modules[new_class.__module__]
    56             kwargs = {"app_label": model_module.__name__.split('.')[-2]}
     56            try:
     57                app_label = model_module.__name__.split('.')[-2]
     58            except IndexError:
     59                if abstract:
     60                    app_label = '_abstract'
     61                else:
     62                    raise ImproperlyConfigured, \
     63                        "Model definitions in '%s' module must reside in an app-level subdirectory within your project or have a defined app_label" \
     64                        % (model_module.__name__)
     65            kwargs = {"app_label": app_label}
    5766        else:
    5867            kwargs = {}
    5968
Back to Top