Created
June 25, 2020 09:03
-
-
Save WinnerOK/b49e460a34897710b6632ac528855b7a to your computer and use it in GitHub Desktop.
[django] export object with dependants
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# https://stackoverflow.com/a/30168962/6766934 | |
from itertools import chain | |
from django.core import serializers | |
from django.contrib.admin.utils import NestedObjects | |
from tasks.models import SectionTypeDescriptor | |
collector = NestedObjects(using="default") # database name | |
collector.collect(SectionTypeDescriptor.objects.all()) | |
objects = list(chain.from_iterable(collector.data.values())) | |
with open("section_type_descriptors.json", "w") as f: | |
f.write(serializers.serialize("json", objects)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment