Created
March 30, 2012 16:47
-
-
Save ptgolden/2252768 to your computer and use it in GitHub Desktop.
South & reversion
This file contains hidden or 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 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