﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
13903	Auto app_label creation fails when model is defined at top-level python modules	petraszd	anonymous	"Pseudo file structure:
{{{
./project
   somefile.py
   /app1
     models.py
}}}

somefile.py has abstract models.Model subclass
models.py uses class from somefile.py

It throws an Exception, because of the way ModelBase class calculates app_label:
{{{
kwargs = {""app_label"": model_module.__name__.split('.')[-2]}
}}}
module is at top level so it has no -2 index fails.

I understand that there so requirements where models should be defined -- but django should not fail (with strange IndexError) too.


I am adding fix and test case.

"	Cleanup/optimization	closed	Database layer (models, ORM)	dev	Normal	fixed			Accepted	1	0	0	1	0	0
