This accounts for none(null) values of rel.to when converting model fields from native

This commit is contained in:
Osiloke Emoekpere 2012-11-04 13:20:10 -05:00
parent 027c9079f6
commit e74772b8a6

View File

@ -211,9 +211,9 @@ class ModelField(WritableField):
def from_native(self, value): def from_native(self, value):
try: try:
rel = self.model_field.rel rel = self.model_field.rel
return rel.to._meta.get_field(rel.field_name).to_python(value)
except: except:
return self.model_field.to_python(value) return self.model_field.to_python(value)
return rel.to._meta.get_field(rel.field_name).to_python(value)
def field_to_native(self, obj, field_name): def field_to_native(self, obj, field_name):
value = self.model_field._get_val_from_obj(obj) value = self.model_field._get_val_from_obj(obj)