Django Selective Dumpdata Django Selective Dumpdata python python

Django Selective Dumpdata


I think django-fixture-magic might be worth a look at.

You'll find some additional background info in Scrubbing your Django database.


This snippet might be helpful for you (it follows relationships and serializes them):

http://djangosnippets.org/snippets/918/

You could use also that management command and override the default managers for whichever models you would like to return custom querysets.


This isn't a simple answer to my question, but I found some interesting docs on Django's built-in natural keys feature, which would allow representing serialized records without the primary key. Unfortunately, it doesn't look like this is fully integrated into dumpdata, and there's an old outstanding ticket to fully rely on natural keys.

It also seems the serializers.serialize() function allows serialization of an arbitrary list of specific model instances.

Presumably, if I implemented a natural_key() method on all my models, and then called serializers.serialize([Users.objects.filter(criteria)]), it should come close to accomplishing what I want. I might have to write a function to crawl all the FK references, and include those in the list of objects passed to serialize().