Skip to content

Instantly share code, notes, and snippets.

@dgouldin
Created September 7, 2011 22:47
Show Gist options
  • Save dgouldin/1202037 to your computer and use it in GitHub Desktop.
Save dgouldin/1202037 to your computer and use it in GitHub Desktop.
Some simple django fixture utils
from django.core import serializers
from django.utils import simplejson
def add_to_fixture(qs, filename):
f = open(filename, 'r')
data_python_existing = simplejson.loads(f.read())
f.close()
data_json_unformatted = serializers.serialize('json', qs)
data_python_new = simplejson.loads(data_json_unformatted)
data_python_existing.extend(data_python_new)
data_json_formatted = simplejson.dumps(data_python_existing, indent=' ')
f = open(filename, 'w')
f.write(data_json_formatted)
f.close()
def make_fixture(qs, filename):
data_json_unformatted = serializers.serialize('json', qs)
data_python = simplejson.loads(data_json_unformatted)
data_json_formatted = simplejson.dumps(data_python, indent=' ')
f = open(filename, 'w')
f.write(data_json_formatted)
f.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment