+ def add_tag(self, obj, tag):
+ """
+ Add tag to an object.
+ """
+ content_type = ContentType.objects.get_for_model(obj)
+ relations = self.intermediary_table_model.objects.filter(
+ content_type__pk=content_type.pk, object_id=obj.pk, tag=tag)
+ if not relations:
+ self.intermediary_table_model.objects.create(tag=tag, content_object=obj)
+