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. |
| 54 | To circumvent this restriction, add an app_label attribute to each model class or to |
| 55 | the model module.""") |