def createTag(request,tag_name): in_db = Tag.objects.get(name=tag_name) if in_db: return HttpResponse(_("Tag already created")) new_tag = Tag(name=tag_name) new_tag.save() return HttpResponse(_("Tag successfully created"))
def linkTag(request, _file, tag): _file = File.objects.get(pk=_file) _tag = Tag.objects.all().filter(name=tag) if not _tag: tag = Tag(name=tag) tag.save() else: tag = _tag[0] _file.tags.add(tag) _file.save() return HttpResponse(_("Tag successfully added to the file"))