Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to modify dumpdata generated django json fixture prior to loading into database
    primarykey
    data
    text
    <p>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.</p> <p>I am using the django deserializer but am having no luck and get an error during the deserialization.</p> <pre><code> File "add_utc_offset_to_fixture.py", line 24, in &lt;module&gt; 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 </code></pre> <p>How do I get around this deserialization error, or alternatively how do I modify this fixtures before loading into the database.</p> <p>I looked into my fixtures and also into the json.py deserializer and do not understand why it needs a module called Image.</p> <p>My code</p> <pre><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 </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload