Django: Data corrupted after loading? (possible programmer error)

Posted by Rosarch on Stack Overflow See other posts from Stack Overflow or by Rosarch
Published on 2010-05-04T13:21:53Z Indexed on 2010/05/04 13:38 UTC
Read the original article Hit count: 175

I may be loading data the wrong way.

excerpt of data.json:

{
    "pk": "1",
    "model": "myapp.Course",
    "fields":
    {
        "name": "Introduction to Web Design",
        "requiredFor": [9],
        "offeringSchool": 1,
        "pre_reqs": [],
        "offeredIn": [1, 5, 9]
    }
},

I run python manage.py loaddata -v2 data:

Installed 36 object(s) from 1 fixture(s)

Then, I go to check the above object using the Django shell:

>>> info = Course.objects.filter(id=1)
>>> info.get().pre_reqs.all()
[<Course: Intermediate Web Programming>] # WRONG! There should be no pre-reqs
>>> from django.core import serializers
>>> serializers.serialize("json", info)
'[{"pk": 1, "model": "Apollo.course", "fields": {"pre_reqs": [11], "offeredIn": [1, 5, 9], "offeringSchool": 1, "name": "Introduction to Web Design", "requiredFor": [9]}}]'

The serialized output of the model is not the same as the input that was given to loaddata. The output has a non-empty pre_req list, whereas the input's pre_reqs field is empty. What am I doing wrong?

© Stack Overflow or respective owner

Related posts about django

Related posts about django-models