diff --git a/beat/web/utils/management/commands/backup.py b/beat/web/utils/management/commands/backup.py index 1245b207e23041d625e5b78c723d5ab01bb49870..c93586954184506b5683b6937e5a2bdd77aea21a 100644 --- a/beat/web/utils/management/commands/backup.py +++ b/beat/web/utils/management/commands/backup.py @@ -158,6 +158,22 @@ class Command(BaseCommand): arguments = copy.deepcopy(dump_arguments) logger.info("Dumping data for `%s' -> `%s'", app, destfile) + if app in only: + + app, model = only[app].split('.') + model = apps.get_model(app, model) + order = ('creation_date',) + + # This will check and correct objects with weird creation + # dates so that the dump order is consistent + while True: + queryset = model.objects.order_by(*order) + err = _check(app, queryset) + if not err: break + + arguments['primary_keys'] = \ + ','.join([str(k.id) for k in queryset]) + arguments['output'] = destfile #new in Django-1.8.x call_command('xdumpdata', only.get(app, app), **arguments) diff --git a/beat/web/utils/management/commands/xdumpdata.py b/beat/web/utils/management/commands/xdumpdata.py index fcddbea38215fa9d8ebba41f0816c4a1f1920bbe..b6b4404f5a2a0ee36caefee800d5b0e6b1388d34 100644 --- a/beat/web/utils/management/commands/xdumpdata.py +++ b/beat/web/utils/management/commands/xdumpdata.py @@ -155,18 +155,17 @@ class Command(BaseCommand): # ################################################### queryset = objects.using(using) - if primary_keys: - # in case the user specifies PKs, respect order - for pk in [int(k) for k in primary_keys]: + if count_only: + yield queryset.count() + elif primary_keys: + for pk in primary_keys: yield queryset.get(pk=pk) - elif count_only: - # ################################################### - # patch for BEAT ends here - # ################################################### - yield queryset.order_by().count() else: for obj in queryset.iterator(): yield obj + # ################################################### + # patch for BEAT ends here + # ################################################### try: self.stdout.ending = None