You are correct.

Based on my experience with natural keys, I would propose improvements
for the documentation [1] - but perhaps these are matters of personal
opinion:
1. mention requirement to use tuple also in serialization section
(currently this is only mentioned in deserialization)
2. rename "natural keys" to "natural relationship keys" (or similar).
Current naming would suggest that pk fields would also use natural
names
3. in the example model define Person first_name and last_name as
unique_together
4. perhaps use "return [self.first_name, self.last_name]" instead of
"return (self.first_name, self.last_name)" in the example so that
reader does not easily fall in to the trailing comma pitfall :)

Thank you very much for your answer. It seems it takes more than a
month to get to know with Python.

[1] http://docs.djangoproject.com/en/dev/topics/serialization/#natural-keys

(I also discovered this by trial and error when I was trying to
deserialize the data, but it was not possible to take back the
question sent to moderation.)

On Apr 16, 2:37 pm, Russell Keith-Magee <freakboy3...@gmail.com>
wrote:
> On Fri, Apr 16, 2010 at 5:26 PM, h-k-ii <hunajaki...@gmail.com> wrote:
> > I find dumpdata output in XML format quite strange for natural keys.
> > Each character in a key reference is wrapped in a <natural>.
>
> > Is this a bug to be reported or a feature?
>
> It certainly doesn't look right; so there is a bug somewhere.
>
> However, it might be in your code. I'm guessing from your serialized
> output that your natural key is drawn from a a single string field on
> your model. Is your natural_key() function defined as:
>
> def natural_key(self):
>     return self.name
>
> or as:
>
> def natural_key(self):
>     return (self.name,)
>
> The first is a string. The second is a tuple containing a single
> element that is a string. Django is expecting the second form;
> however, because strings are iterable objects, the first is also a
> valid (albeit incorrect) natural key definition, consisting of as many
> natural keys as there are letters in 'self.name'.
>
> Yours,
> Russ Magee %-)
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group 
> athttp://groups.google.com/group/django-users?hl=en.

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

Reply via email to