views:

84

answers:

1

Here are some models I am trying to load data for:

class School(models.Model):
    name = models.CharField(max_length=200)

    def __unicode__(self):
        return self.name

class RequirementSet(models.Model):
    offeringSchool = models.ForeignKey(School)
    name = models.CharField(max_length=200)

    def __unicode__(self):
        return "%s at %s" % (self.name, self.offeringSchool)

Here is the JSON I am trying to use to initialize them:

// data.json

[
    {
        "pk": "1",
        "model": "myapp.School",
        "fields":
        {
            "name": "Princeton"
        }
    },
    {
        "pk": "1",
        "model": "myapp.RequirementSet",
        "fields":
        {
            "name": "Computer Science",
            "offeringSchool": 1
        }
    }
]

I run python manage.py loaddata data.json, and I get this error:

...
Checking absolute path for fixtures...
Trying absolute path for data.json fixture 'data'...
Installing json fixture 'data' from absolute path.
Problem installing fixture 'data.json': Traceback (most recent call last):
  File "C:\Python26\lib\site-packages\django\core\management\commands\loaddata.p
y", line 150, in handle
    for obj in objects:
  File "C:\Python26\lib\site-packages\django\core\serializers\json.py", line 41,
 in Deserializer
    for obj in PythonDeserializer(simplejson.load(stream)):
  File "C:\Python26\lib\json\__init__.py", line 267, in load
    parse_constant=parse_constant, **kw)
  File "C:\Python26\lib\json\__init__.py", line 307, in loads
    return _default_decoder.decode(s)
  File "C:\Python26\lib\json\decoder.py", line 319, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "C:\Python26\lib\json\decoder.py", line 338, in raw_decode
    raise ValueError("No JSON object could be decoded")
ValueError: No JSON object could be decoded

What am I doing wrong?

Interacting with these models through the shell and the admin UI works fine.

+1  A: 

The JSON format is not allowed to have comments. Remove the // data.json line and it should work.

interjay
Oh yes! sorry for my bad answer. a bit tired :)However, I keep recommending to dumpdata to see the expected format
luc