#9422: Incorrect handling of foreign keys by serializers
---------------------------+------------------------------------------------
Reporter: etianen | Owner: nobody
Status: new | Milestone:
Component: Serialization | Version: 1.0
Keywords: | Stage: Unreviewed
Has_patch: 1 |
---------------------------+------------------------------------------------
When a foreign key points to a remote object via a non-primary key field,
the Python serializer and XML serializer classes can sometimes handle this
incorrectly.
This occurs when the primary key of the related object is a OneToOneField,
as is the case for model inheritance. In this case, the serializer will
store the __unicode__ version of the primary key, rather than the primary
key itself.
As an example:
{{{
class Foo(models.Model):
pass
class Bar(Foo):
name = models.CharField(max_length=244)
slug = models.SlugField(unique=True)
def __unicode__(self):
return self.name
class Wibble(models.Model):
bar = models.ForeignKey(Bar, to_field="slug")
}}}
when a Wibble instance is serialized, the value of the 'bar' property will
be serialized as the result of calling __unicode__ on the referenced Bar.
This problem can be resolved with the attached patch.
--
Ticket URL: <http://code.djangoproject.com/ticket/9422>
Django <http://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django updates" 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-updates?hl=en
-~----------~----~----~----~------~----~------~--~---