Skip to content

Commit

Permalink
Merge pull request #670 from mzaforas/patch-1
Browse files Browse the repository at this point in the history
Update syncdata.py to allow skip remove objects
  • Loading branch information
trbs committed May 7, 2015
2 parents 23115ec + f95335f commit 78b52d1
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion django_extensions/management/commands/syncdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import sys
from contextlib import contextmanager
from functools import wraps
from optparse import make_option

import six
from django.core.management.base import BaseCommand
Expand Down Expand Up @@ -50,6 +51,12 @@ class Command(BaseCommand):
help = 'Makes the current database have the same data as the fixture(s), no more, no less.'
args = "fixture [fixture ...]"

option_list = BaseCommand.option_list + (
make_option('--skip-remove', action='store_false',
dest='remove', default=True,
help='Avoid remove any object from db'),
)

def remove_objects_not_in(self, objects_to_keep, verbosity):
"""
Deletes all the objects in the database that are not in objects_to_keep.
Expand Down Expand Up @@ -167,7 +174,8 @@ def handle(self, *fixture_labels, **options):
models.add(class_)
obj.save()

self.remove_objects_not_in(objects_to_keep, verbosity)
if options.get('remove'):
self.remove_objects_not_in(objects_to_keep, verbosity)

label_found = True
except (SystemExit, KeyboardInterrupt):
Expand Down

0 comments on commit 78b52d1

Please sign in to comment.