﻿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
6961	loaddata fails if models directory instead of models.py	Phil Davis	nobody	"If the models for an app have been split into multiple files within a models subdirectory of the app then loaddata looks for fixtures in appname/models/fixtures instead of appname/fixtures.

To reproduce:

{{{
   django-admin.py startproject proj1
   cd proj1
   django-admin.py startapp foo
   cd foo
   vi ../settings.py  # set INSTALLED_APPS to just proj1.foo
   mkdir fixtures
   touch fixtures/abc.json

   ../manage.py loaddata --verbosity=2 abc.json
   Problem installing fixture '/data/home/leotest/projects/proj1/../proj1/foo/fixtures/abc.json': No JSON object could be decoded
   # location is correct, error is because file is empty

   rm models.py
   mkdir models
   touch models/__init__.py
   ../manage.py loaddata --verbosity=2 abc.json

   Loading 'abc' fixtures...
   Checking '/data/home/leotest/projects/proj1/../proj1/foo/models/fixtures' for fixtures...
   Trying '/data/home/leotest/projects/proj1/../proj1/foo/models/fixtures' for json fixture      'abc'...
   No json fixture 'abc' in '/data/home/leotest/projects/proj1/../proj1/foo/models/fixtures'.
   Checking absolute path for fixtures...
   Trying absolute path for json fixture 'abc'...
   No json fixture 'abc' in absolute path.
   No fixtures found.
}}}


The problem is that loaddata uses {{{app.__file__}}} and app object is actually the app.models
module rather than the app module. This is around line 141 in core/management/commands/loaddata.py.

Note that setting app_label in Meta subclass for each model has no bearing on this problem.
   "		closed	Core (Management commands)	dev		fixed	loaddata	zilingzhao@… mjmalone@…	Ready for checkin	1	0	0	0	0	0
