Ticket #16208: 16208.patch
File 16208.patch, 1.6 KB (added by , 13 years ago) |
---|
-
django/core/serializers/python.py
110 110 if hasattr(field.rel.to._default_manager, 'get_by_natural_key'): 111 111 if hasattr(field_value, '__iter__'): 112 112 obj = field.rel.to._default_manager.db_manager(db).get_by_natural_key(*field_value) 113 value = getattr(obj, field.rel.field_name)114 # If this is a natural foreign key to an object that115 # has a FK/O2O as the foreign key, use the FK value116 if field.rel.to._meta.pk.rel:117 value = value.pk118 113 else: 119 value = field.rel.to._meta.get_field(field.rel.field_name).to_python(field_value) 114 obj = field.rel.to._default_manager.db_manager(db).get_by_natural_key(field_value) 115 value = getattr(obj, field.rel.field_name) 116 # If this is a natural foreign key to an object that 117 # has a FK/O2O as the foreign key, use the FK value 118 if field.rel.to._meta.pk.rel: 119 value = value.pk 120 120 data[field.attname] = value 121 121 else: 122 122 data[field.attname] = field.rel.to._meta.get_field(field.rel.field_name).to_python(field_value)