Skip to content

Instantly share code, notes, and snippets.

@ptgolden
Created March 30, 2012 16:47
Show Gist options
  • Save ptgolden/2252768 to your computer and use it in GitHub Desktop.
Save ptgolden/2252768 to your computer and use it in GitHub Desktop.
South & reversion
from reversion.models import Version
import json
object_fields = {}
for v in Version.objects.all():
# For now, only dealing with versions that correspond to a still-existing
# model instance, since it's easier to get the model class with that info
if v.object:
v_data = json.loads(v.serialized_data)
object_name = v.object._meta.object_name
if not object_fields.has_key(object_name):
fields = v.object._meta.get_all_field_names()
object_fields[object_name] = fields
approved_fields = object_fields[object_name]
version_fields = v_data[0]['fields']
bad_fields = [f for f in version_fields if f not in approved_fields]
for field_to_remove in bad_fields:
del(v_data[0]['fields'][field_to_remove])
v.serialized_data = json.dumps(v_data)
v.save()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment