'Called to handle a ManyToManyField. Related objects are only
serialized as references to the object\'s PK (i.e. the related *data*
is not dumped, just the relation).'

def handle_m2m_field(self, obj, field):

    if field.rel.through._meta.auto_created:
        self._start_relational_field(field)
        if (self.use_natural_keys and hasattr(field.rel.to, u'natural_key')):
            def handle_m2m(value):
                natural = value.natural_key()
                self.xml.startElement(u'object', {})
                for key_value in natural:
                    self.xml.startElement(u'natural', {})
                    self.xml.characters(smart_text(key_value))
                    self.xml.endElement(u'natural')
                self.xml.endElement(u'object')
        else:
            def handle_m2m(value):
                self.xml.addQuickElement(u'object', attrs={u'pk': smart_text(value._get_pk_val())})
        for relobj in getattr(obj, field.name).iterator():
            handle_m2m(relobj)
        self.xml.endElement(u'field')
