Skip to content

Instantly share code, notes, and snippets.

@czpython
Last active March 3, 2024 14:22
Show Gist options
  • Save czpython/b94c346e4b6cac473bff to your computer and use it in GitHub Desktop.
Save czpython/b94c346e4b6cac473bff to your computer and use it in GitHub Desktop.
create fixture of django filer
from django.core import serializers
from django.db.models import get_app, get_models
from django.db.models.query import QuerySet
def export_filer_models(output_file=None):
"""
Exports filer models to output_file.
"""
app = get_app('filer')
model_list = get_models(app)
# We handle filer differently because django-polymorphic interferes when serializing.
def get_objects():
for model in model_list:
# Hack because of django-polyporphic D:<
model.objects.queryset_class = QuerySet
for obj in model.objects.iterator():
yield obj
serializers.serialize('json', get_objects(), indent=2, use_natural_keys=True, stream=output_file)
@vasdee
Copy link

vasdee commented Jul 12, 2016

@czpython Cheers for this, I don't know how i found this, but it solved an issue I was facing with dumpdata and django-filer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment