Search code examples
pythondjangoviewmodelsfixtures

Possible way to create fixtures in the view with Django?


as the title says. Is there a possible way to create fixtures in the view with Django?

Thanks a lot!


Solution

  • You can call dumpdata in your view with call_command (docs here: https://docs.djangoproject.com/en/dev/ref/django-admin/#running-management-commands-from-your-code).

    See this answer: How to use call_command with dumpdata command to save json to file