Skip to content

Instantly share code, notes, and snippets.

@ghing
Created May 23, 2013 20:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ghing/5639148 to your computer and use it in GitHub Desktop.
Save ghing/5639148 to your computer and use it in GitHub Desktop.
Create a fixture of all HtmlAsset models that include 'script' in the body
#!/usr/bin/env python
# Create a fixture of all HtmlAsset models that include 'script' in the
# body
# Usage: dump_script_assets.py | python -mjson.tool > script_assets.json
from django.core.management import setup_environ
# Edit this to use a particular settings module
import settings.dev
setup_environ(settings.dev)
from django.core import serializers
from storybase_asset.models import Asset, HtmlAsset
to_serialize = []
for ha in HtmlAsset.objects.all():
if 'script' in ha.body or 'SCRIPT' in ha.body:
to_serialize.append(ha)
# Since we're using multi-table inheritance, we need to get the
# parent model as well
a = Asset.objects.get(pk=ha.pk)
# Clobber the owner attribute so there's not a dependency when
# importing the
a.owner = None
to_serialize.append(a)
# Also get the translations
for atrans in ha._get_translated_manager().all():
to_serialize.append(atrans)
print serializers.serialize("json", to_serialize)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment