Ticket #2894: deserialize_none_fk.diff

File deserialize_none_fk.diff, 909 bytes (added by andrew@…, 18 years ago)

Simple patch to handle None case.

  • django/core/serializers/xml_serializer.py

     
    166166        # If it doesn't exist, set the field to None (which might trigger
    167167        # validation error, but that's expected).
    168168        RelatedModel = self._get_model_from_node(node, "to")
    169         return RelatedModel.objects.get(pk=getInnerText(node).strip().encode(self.encoding))
     169        # Check if there is a child node named 'None', returning None if so.
     170        if len(node.childNodes) == 1 and node.childNodes[0].nodeName == 'None':
     171            return None
     172        else:
     173            return RelatedModel.objects.get(pk=getInnerText(node).strip().encode(self.encoding))
    170174       
    171175    def _handle_m2m_field_node(self, node):
    172176        """
Back to Top