Hi,

I have searched high and low to an answer to this, but have been
unable too turn anything up. Apologies if I have overlooked an answer
or explanation elsewhere.

I have set up a very simple model as follows:
---------------------------------------------------------------------------
from django.db import models
class TestManager(models.Manager):
    def get_by_natural_key(self, name):
        return self.get(name=name,)

class Test(models.Model):
    name = models.CharField(max_length = 100, unique = True)
    date = models.DateField()

    def __unicode__(self):
        return self.name

    def natural_key(self):
        return (self.name)

class InstanceManager(models.Manager):
    def get_by_natural_key(self, name):
        return self.get(name=name,)

class Instance(models.Model):
    name = models.CharField(max_length = 100, unique = True)
    test = models.ManyToManyField(Test)
    date = models.DateField()

    def __unicode__(self):
        return self.name

    def natural_key(self):
        return (self.name)
---------------------------------------------------------------

looking at the admin interface I am able to add a couple of
'tests' (test 1 and test 2). I am then able to add an instance which
is linked to both test 1 and test 2. If I dump the data to YAML format
then I get the following (for the two tables in question):

---------------------------------------------------------------
- fields: {date: 2012-03-26, name: test 1}
  model: TempDB.test
  pk: 1
- fields: {date: 2012-03-26, name: test 2}
  model: TempDB.test
  pk: 2
- fields:
    date: 2012-03-26
    name: Instance 1
    test: [test 1, test 2]
  model: TempDB.instance
  pk: 1
---------------------------------------------------------------

This is roughly what I would expect to see, although the documentation
does not explicitly state that a manytomany serialization will be a
multi-element list, it seems to be a reasonable assumption.

When I try to perform a loaddata with this output (and after manually
deleting the tables from the admin interface, to be sure). I get the
following error:

Problem installing fixture '/home/XXXX/workspace/THMDB/THMDB/TempDB/
fixtures/test.yaml': Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/Django-1.4-py2.7.egg/
django/core/management/commands/loaddata.py", line 190, in handle
    for obj in objects:
  File "/usr/local/lib/python2.7/dist-packages/Django-1.4-py2.7.egg/
django/core/serializers/pyyaml.py", line 62, in Deserializer
    raise DeserializationError(e)
DeserializationError: [u"'test 1' value must be an integer."]

What exactly have I done wrong? I suspect I have made an error in
defining the managers. I have defined two as I planned to link too
instances from another table. I left in the definition in case it is
the cause of the error. However it still does the same thing if I
comment it out.

I am running Django 1.4 on python 2.7 under Ubuntu 11.10.

Many thanks for your help.

Stephen

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to