1
0
mirror of https://github.com/django/django.git synced 2025-10-29 00:26:07 +00:00

The first step in fixing a group of problems related to outputting a proper

"value" for a field that is a relation to another model.

This part adds the utility method on Model that should help in general.Also
cleans up the slightly ugly mess from r8957.


git-svn-id: http://code.djangoproject.com/svn/django/trunk@9601 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Malcolm Tredinnick
2008-12-08 08:15:37 +00:00
parent fa7aa7255c
commit d662ef5540
3 changed files with 12 additions and 7 deletions

View File

@@ -624,13 +624,7 @@ class ModelChoiceIterator(object):
def choice(self, obj):
if self.field.to_field_name:
# FIXME: The try..except shouldn't be necessary here. But this is
# going in just before 1.0, so I want to be careful. Will check it
# out later.
try:
key = getattr(obj, self.field.to_field_name).pk
except AttributeError:
key = getattr(obj, self.field.to_field_name)
key = obj.serializable_value(self.field.to_field_name)
else:
key = obj.pk
return (key, self.field.label_from_instance(obj))