diff --git a/django/core/management/commands/loaddata.py b/django/core/management/commands/loaddata.py
index a6a7871..9ba3748 100644
a
|
b
|
class Command(BaseCommand):
|
14 | 14 | make_option('--verbosity', action='store', dest='verbosity', default='1', |
15 | 15 | type='choice', choices=['0', '1', '2'], |
16 | 16 | help='Verbosity level; 0=minimal output, 1=normal output, 2=all output'), |
| 17 | make_option('--noclobber', action='store_true', dest='noclobber', |
| 18 | default=False, help='Preserve existing data'), |
17 | 19 | ) |
18 | 20 | help = 'Installs the named fixture(s) in the database.' |
19 | 21 | args = "fixture [fixture ...]" |
… |
… |
class Command(BaseCommand):
|
26 | 28 | |
27 | 29 | self.style = no_style() |
28 | 30 | |
| 31 | noclobber = bool(options.get('noclobber', False)) |
29 | 32 | verbosity = int(options.get('verbosity', 1)) |
30 | 33 | show_traceback = options.get('traceback', False) |
31 | 34 | |
… |
… |
class Command(BaseCommand):
|
108 | 111 | else: |
109 | 112 | fixture_count += 1 |
110 | 113 | objects_in_fixture = 0 |
| 114 | objects_saved = 0 |
111 | 115 | if verbosity > 0: |
112 | 116 | print "Installing %s fixture '%s' from %s." % \ |
113 | 117 | (format, fixture_name, humanize(fixture_dir)) |
… |
… |
class Command(BaseCommand):
|
116 | 120 | for obj in objects: |
117 | 121 | objects_in_fixture += 1 |
118 | 122 | models.add(obj.object.__class__) |
119 | | obj.save() |
120 | | object_count += objects_in_fixture |
| 123 | if noclobber: |
| 124 | try: |
| 125 | obj.object.__class__.objects.get(pk=obj.object.pk) |
| 126 | except obj.object.__class__.DoesNotExist: |
| 127 | obj.save() |
| 128 | objects_saved += 1 |
| 129 | else: |
| 130 | obj.save() |
| 131 | objects_saved += 1 |
| 132 | object_count += objects_saved |
121 | 133 | label_found = True |
122 | 134 | except (SystemExit, KeyboardInterrupt): |
123 | 135 | raise |