def check_object_deleted_tags(sender, **kwargs): '''Each object that gets deleted is checked for association with tags. If this associations exist they are deleted''' # Get the tagged items list obj = kwargs['instance'] content_type = ContentType.objects.get_for_model(obj) try: tag_list = TaggedItem.objects.filter( content_type__exact = content_type, object_id__exact = obj.id ) except AttributeError: # The django session onjects have no id attribute return # Delete the tags for tagged_item in tag_list: del_tagged_item(tagged_item)
def untag_object(request, item_id ): context = {} try: tagged_item = TaggedItem.objects.get(pk = item_id) except ObjectDoesNotExist: context['success'] = False context['message'] = 'Etiqueta não existe' return context user = tagged_item.tag.user if request.user != user: raise PermissionDenied del_tagged_item( tagged_item ) context['success'] = True context['message'] = 'Etiqueta removida' return context