﻿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
1658	db.models.base.ModelBase.__new__ fails to deduce app_label with model packages	bjorn@…	nobody	"In the latest magic-removal branch, if models are in a separate directory (package) instead of just a module they will have one more component in their path.

{{{db.models.base.ModelBase.__new__ tries}}} to deduce the app_label from the model's module, but fails in this case.  It will call {{{register_module()}}} with the parent directory as its app_label, but in this case the parent directory is the model package itself, resulting in it registering the module wrongly.  The code in question is:

{{{
        if getattr(new_class._meta, 'app_label', None) is None:
            # Figure out the app_label by looking one level up.
            # For 'django.contrib.sites.models', this would be 'sites'.
            new_class._meta.app_label = model_module.__name__.split('.')[-2]
}}}

For example, a model in {{{myproj/apps/myapp/models/mymodel.py}}} will register itself as belonging to {{{myproj.apps.myapp.models}}} with app_label models.

-- Bjorn"	defect	closed	Core (Other)	dev	major	duplicate	egg, distutils, pkg_resources	erob@…	Accepted	0	0	0	0	0	0
