djangodumpdata

Excluding multiple app in django dumpdata using call_command


I'm using call_command to launch a datadump, I would like to exclude multiple apps, so if I was not using call_command, I would do it like the django documentation tell to do it :

python manage.py dumpdata --format json -e app1 -e app2

But in call_command I don't know how I should call it :

from django.core.management import call_command
call_command("dumpdata", format="json", ?)

What is not working :

call_command("dumpdata", format="json", exclude="app1")
call_command("dumpdata", format="json", exclude="app1 app2")
# CommandError: No installed app with label 'a'.

call_command("dumpdata", format="json", e="app1")
call_command("dumpdata", format="json", e="app1 app2")
# Does not fail but does not exclude anything either

call_command("dumpdata", format="json", e="app1", e="app2")
# SyntaxError: keyword argument repeated

Is it even possible to exclude something from dumpdata using call_command ?

Thanks in advance.


Solution

  • You should use a list to pass the argument like this :

    call_command("dumpdata", format="json", e=["app1", "app2"])
    

    The error No installed app with label 'a', hint at how the dumpdata command is handled by Django (the string "app1" is treated as a list).