In addition to writing custom django-admin commands, which is pretty well documented, I would like to be able to override an existing command, like manage.py loaddata (fixture)
so I could add some further treatment after that fixtures would have been loaded into my database.
I guess I would have to write a custom command that first calls 'loaddata' and then does its own treatment. Is there a neat way to do things so?
Is there a better solution?
Thanks to Moses link to other SO answers I eventually managed to write a template for additional treatment to a loaddata
command. Here is a snippet which does the trick:
"""
Additional treatment for the loaddata command.
Location example: project/app/management/commands/loaddata.py
"""
from django.core.management.base import BaseCommand, CommandError
from django.core.management.commands import loaddata
class Command(loaddata.Command):
def handle(self, *args, **options):
super(Command, self).handle(*args, **options)
self.stdout.write("Here is a further treatment! :)")
don't forget to put your application on top in the INSTALLED_APPS configuration
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With