From de720afd0edda00fbfb95adc1030b62b9070d4d5 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Sun, 25 Apr 2021 10:13:31 +1000 Subject: [PATCH] Exclude unwanted modules from import / export --- tasks.py | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/tasks.py b/tasks.py index 316e9b4bfb..a6304467d1 100644 --- a/tasks.py +++ b/tasks.py @@ -232,6 +232,30 @@ def coverage(c): # Generate coverage report c.run('coverage html') + +def content_excludes(): + """ + Returns a list of content types to exclude from import/export + """ + + excludes = [ + "contenttypes", + "auth.permission", + "error_report.error", + "admin.logentry", + "django_q.schedule", + "django_q.task", + "django_q.ormq", + ] + + output = "" + + for e in excludes: + output += f"--exclude {e} " + + return output + + @task(help={'filename': "Output filename (default = 'data.json')"}) def export_records(c, filename='data.json'): """ @@ -253,7 +277,7 @@ def export_records(c, filename='data.json'): print("Cancelled export operation") sys.exit(1) - cmd = f'dumpdata --exclude contenttypes --exclude auth.permission --indent 2 --output {filename}' + cmd = f"dumpdata --indent 2 --output {filename} {content_excludes()}" manage(c, cmd, pty=True) @@ -273,7 +297,7 @@ def import_records(c, filename='data.json'): print(f"Importing database records from '{filename}'") - cmd = f'loaddata {filename}' + cmd = f"loaddata {filename} -i {content_excludes()}" manage(c, cmd, pty=True)