diff --git a/django/core/management/commands/loaddata.py b/django/core/management/commands/loaddata.py index 464e19ce0c..32a676d846 100644 --- a/django/core/management/commands/loaddata.py +++ b/django/core/management/commands/loaddata.py @@ -122,6 +122,7 @@ class Command(BaseCommand): """ Loads fixtures files for a given label. """ + show_progress = self.verbosity >= 3 for fixture_file, fixture_dir, fixture_name in self.find_fixtures(fixture_label): _, ser_fmt, cmp_fmt = self.parse_name(os.path.basename(fixture_file)) open_method, mode = self.compression_formats[cmp_fmt] @@ -144,6 +145,11 @@ class Command(BaseCommand): self.models.add(obj.object.__class__) try: obj.save(using=self.using) + if show_progress: + self.stdout.write( + '\rProcessed %i object(s).' % loaded_objects_in_fixture, + ending='' + ) except (DatabaseError, IntegrityError) as e: e.args = ("Could not load %(app_label)s.%(object_name)s(pk=%(pk)s): %(error_msg)s" % { 'app_label': obj.object._meta.app_label, @@ -152,7 +158,8 @@ class Command(BaseCommand): 'error_msg': force_text(e) },) raise - + if objects and show_progress: + self.stdout.write('') # add a newline after progress indicator self.loaded_object_count += loaded_objects_in_fixture self.fixture_object_count += objects_in_fixture except Exception as e: diff --git a/tests/fixtures/tests.py b/tests/fixtures/tests.py index f809c349f7..8eec3145b8 100644 --- a/tests/fixtures/tests.py +++ b/tests/fixtures/tests.py @@ -342,6 +342,16 @@ class FixtureLoadingTests(DumpDataAssertMixin, TestCase): '', ]) + def test_loaddata_verbosity_three(self): + output = six.StringIO() + management.call_command('loaddata', 'fixture1.json', verbosity=3, stdout=output, stderr=output) + command_output = output.getvalue() + self.assertIn( + "\rProcessed 1 object(s).\rProcessed 2 object(s)." + "\rProcessed 3 object(s).\rProcessed 4 object(s).\n", + command_output + ) + def test_loading_using(self): # Load db fixtures 1 and 2. These will load using the 'default' database identifier explicitly management.call_command('loaddata', 'db_fixture_1', verbosity=0, using='default')