def _add_tags(self, instance, new_tags): if not new_tags: return [] ctype = ContentType.objects.get_for_model(instance) #Create mapping for x in new_tags: Item.objects.create(content_object=instance, tag=x) #send signal item_tagged.send(sender=self.model, action='create', content_type=ctype, tags=new_tags, instance=instance) return [x.name for x in new_tags]
def _remove_tags(self, instance, tags): if not tags: return [] ctype = ContentType.objects.get_for_model(instance) #Delete mapping Item.objects.filter(content_type__pk=ctype.id, object_id=instance.pk, tag__in=[x.pk for x in tags] ).delete() #send signal item_tagged.send(sender=self.model, action='remove', content_type=ctype, tags=tags, instance=instance) return [x.name for x in tags]