Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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)
@Vido

This comment has been minimized.

Copy link

@Vido Vido commented Dec 27, 2014

Hey @czpython it works, but some headers are missing:

from django.core import serializers

and than:

serializers.serialize('json', get_objects(), indent=2, use_natural_keys=True, stream=output_file)
@czpython

This comment has been minimized.

Copy link
Owner Author

@czpython czpython commented Jun 24, 2015

Updated, thanks!

@vasdee

This comment has been minimized.

Copy link

@vasdee 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
You can’t perform that action at this time.