I am a relative django newbie. I have a json fixture for the django.contrib.auth.user objects from an existing database that I want to load into my test app. The specific field I want to modify are all the Datetime Fields that do not have UTC offsets built into them. I want to add these UTC offsets using a python script.
I am using the django deserializer but am having no luck and get an error during the deserialization.
File "add_utc_offset_to_fixture.py", line 24, in <module>
for obj in serializers.deserialize("json", json_fixture):
File "/Users/hari/.virtualenvs/bsc2/lib/python2.7/site-packages/django/core/serializers/json.py", line 47, in Deserializer
raise DeserializationError(e)
django.core.serializers.base.DeserializationError: No module named Image
How do I get around this deserialization error, or alternatively how do I modify this fixtures before loading into the database.
I looked into my fixtures and also into the json.py deserializer and do not understand why it needs a module called Image.
My code
# This program reads in a json fixture with naive Datetime field and converts it into a UTC aware Datetime field
# For Documentation on this see https://docs.djangoproject.com/en/dev/topics/i18n/timezones/#time-zones-migration-guide
import sys,os
# Sets the django settings module
dir_two_steps_up_from_me = os.path.join(os.path.split(os.path.dirname(os.path.abspath(__file__)))[-2])
print "Adding %s to sys.path" % dir_two_steps_up_from_me
sys.path.append(dir_two_steps_up_from_me)
from bsc2 import settings
from django.core.management import setup_environ
# Deprecated but still using
setup_environ(settings)
from django.core import serializers
from django.contrib.auth.models import User
json_fixture = None
try:
json_fixture = open(sys.argv[1],"rb")
except IndexError,IOError:
print "Please give json fixture"
exit()
for obj in serializers.deserialize("json", json_fixture):
# Getting deserialization error when this executes
print obj.first_name
# TODO Code to change naive time in last_login to UTC time