Last active
January 10, 2017 00:40
-
-
Save jhinds/eca3dcc4d17b68fe944945df4e9845a0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from optparse import make_option | |
from django.core.management.commands.loaddata import Command as LoadDataCommand | |
class Command(LoadDataCommand): | |
option_list = LoadDataCommand.option_list + ( | |
make_option('-e', '--exclude', action='append', | |
help='Exclude given fixture/s from being loaded'), | |
) | |
def handle(self, *fixture_labels, **options): | |
self.exclude = options.get('exclude') | |
return super(Command, self).handle(*fixture_labels, **options) | |
def find_fixtures(self, *args, **kwargs): | |
updated_fixtures = [] | |
fixture_files = super(Command, self).find_fixtures(*args, **kwargs) | |
for fixture_file in fixture_files: | |
file, directory, name = fixture_file | |
# exclude a matched file path, directory or name (filename without extension) | |
if file in self.exclude or directory in self.exclude or name in self.exclude: | |
if self.verbosity >= 1: | |
self.stdout.write('Fixture skipped (excluded: %s, matches %s)' % | |
(self.exclude, [file, directory, name])) | |
else: | |
updated_fixtures.append(fixture_file) | |
return updated_fixtures |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment