Answer the question
In order to leave comments, you need to log in
How to pass stdout data to stringio?
There is a custom command that calls the dumpdata command. It is necessary to transfer the returned data from this call to stringio, how can I do this?
fake_file = io.StringIO()
call_command('dumpdata', stdout=fake_file)
print(fake_file.read()) #Ноль эффекта
Answer the question
In order to leave comments, you need to log in
Well, why these crutches? If you need to get json of all project data, use a serializer, as the dumpdata command itself does:
from django.apps import apps
from django.core import serializers
# Получаем список всех моделей всех приложений из INSTALLED_APPS
# и фильтруем django'вские
models = [model for model in apps.get_models() if not model.__module__.startswith('django')]
# Сериалзиуем в json полный QuerySet каждой модели
dump = ''
for m in models:
dump += serializers.serialize('json', m._default_manager.all())
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question