Ticket #11943: serializer.diff

File serializer.diff, 1.4 KB (added by termie, 15 years ago)
  • django/core/serializers/python.py

     
    3535        self._current = None
    3636
    3737    def handle_field(self, obj, field):
    38         value = field._get_val_from_obj(obj)
    39         # Protected types (i.e., primitives like None, numbers, dates,
    40         # and Decimals) are passed through as is. All other values are
    41         # converted to string first.
    42         if is_protected_type(value):
    43             self._current[field.name] = value
    44         else:
    45             self._current[field.name] = field.value_to_string(obj)
     38        try:
     39          value = field._get_val_from_obj(obj)
     40          # Protected types (i.e., primitives like None, numbers, dates,
     41          # and Decimals) are passed through as is. All other values are
     42          # converted to string first.
     43          if is_protected_type(value):
     44              self._current[field.name] = value
     45          else:
     46              self._current[field.name] = field.value_to_string(obj)
     47        except AttributeError:
     48          self._current[field.name] = smart_unicode(getattr(obj, field.name),
     49                                                            strings_only=True)
    4650
    4751    def handle_fk_field(self, obj, field):
    4852        related = getattr(obj, field.name)
Back to Top