From 12d364a9b0b4bf820a68104a64ba312c7290518b Mon Sep 17 00:00:00 2001 From: Florian Apolloner Date: Tue, 20 Aug 2013 19:03:33 +0200 Subject: [PATCH] [1.6.x] Fixed #20933 -- Allowed loaddata to load fixtures from relative paths. Backport of 6e846f7627ecf0dc15053624a23bfbf47535972d from master. --- django/core/management/commands/loaddata.py | 2 +- docs/howto/initial-data.txt | 4 ++-- tests/fixtures_regress/models.py | 6 ------ tests/fixtures_regress/tests.py | 17 ++++++++++++++++- 4 files changed, 19 insertions(+), 10 deletions(-) diff --git a/django/core/management/commands/loaddata.py b/django/core/management/commands/loaddata.py index 6856e85e45..e8ec992af4 100644 --- a/django/core/management/commands/loaddata.py +++ b/django/core/management/commands/loaddata.py @@ -181,7 +181,7 @@ class Command(BaseCommand): if self.verbosity >= 2: self.stdout.write("Loading '%s' fixtures..." % fixture_name) - if os.path.isabs(fixture_name): + if os.path.sep in fixture_name: fixture_dirs = [os.path.dirname(fixture_name)] fixture_name = os.path.basename(fixture_name) else: diff --git a/docs/howto/initial-data.txt b/docs/howto/initial-data.txt index cea07bfea3..c84664fd9a 100644 --- a/docs/howto/initial-data.txt +++ b/docs/howto/initial-data.txt @@ -90,8 +90,8 @@ fixtures. You can set the :setting:`FIXTURE_DIRS` setting to a list of additional directories where Django should look. When running :djadmin:`manage.py loaddata `, you can also -specify an absolute path to a fixture file, which overrides searching -the usual directories. +specify a path to a fixture file, which overrides searching the usual +directories. .. seealso:: diff --git a/tests/fixtures_regress/models.py b/tests/fixtures_regress/models.py index 7ba069ad08..ee93de2293 100644 --- a/tests/fixtures_regress/models.py +++ b/tests/fixtures_regress/models.py @@ -39,12 +39,6 @@ class Stuff(models.Model): class Absolute(models.Model): name = models.CharField(max_length=40) - load_count = 0 - - def __init__(self, *args, **kwargs): - super(Absolute, self).__init__(*args, **kwargs) - Absolute.load_count += 1 - class Parent(models.Model): name = models.CharField(max_length=10) diff --git a/tests/fixtures_regress/tests.py b/tests/fixtures_regress/tests.py index 1d0fb9e724..58339c9280 100644 --- a/tests/fixtures_regress/tests.py +++ b/tests/fixtures_regress/tests.py @@ -148,7 +148,22 @@ class TestFixtures(TestCase): load_absolute_path, verbosity=0, ) - self.assertEqual(Absolute.load_count, 1) + self.assertEqual(Absolute.objects.count(), 1) + + def test_relative_path(self): + directory = os.path.dirname(upath(__file__)) + relative_path = os.path.join('fixtures', 'absolute.json') + cwd = os.getcwd() + try: + os.chdir(directory) + management.call_command( + 'loaddata', + relative_path, + verbosity=0, + ) + finally: + os.chdir(cwd) + self.assertEqual(Absolute.objects.count(), 1) def test_unknown_format(self): """