Created
September 7, 2011 22:47
-
-
Save dgouldin/1202037 to your computer and use it in GitHub Desktop.
Some simple django fixture utils
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
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