def save_relation_data(self, instance, name, value):
        instance_field = getattr(instance, name)

        for related in instance_field.all():
            if related.object not in value:
                instance_field.remove(related)

        for related in value:
            instance_field.connect(related)
Search into PGXN.
dataset/ETHPy150Open yourlabs/django-autocomplete-light/src/dal_genericm2m/fields.py/GenericM2MFieldMixin.save_relation_data--crossover with--dataset/ETHPy150Open dvarrazzo/pgxnclient/pgxnclient/api.py/Api.search