Skip to content

Unclear how to easily add multiple tags to object #9

@mozrat

Description

@mozrat

I'm playing with django-tagging-ng and I've written a view function to add new tags to an object

def add(request):
    if request.method == 'POST':
        form = TagForm(request.POST)
        if form.is_valid():
            model = models.get_model(request.GET.get('app_label'), request.GET.get('object_name'))            
            record = model.objects.get(id=request.GET.get('id', None))
            tags = form.cleaned_data['tags']
            Tag.objects.add_tag(record, tags)
    referer = request.META.get('HTTP_REFERER', '/')
    return HttpResponseRedirect(referer)

This is supposed to add a tag to an object. It works fine in the case that form.cleaned_data['tags'] contains a single tag.

I've also succeeded in adding multiple tags by iterating over parse_tag_input(form.cleaned_data['tags']) and adding a single tag in each iteration

BUT.. When the tag input is like '''one two "three four"''' I fail because parse_tag_input is treating "three four" as a single tag.

Inside add_tag it fails if a tag has multiple elements.

What is the most convenient way to append tags to a list of existing tags for an object and to handle inputs like ''' one two "three four"'''

Sorry if this isn't clear - it actually makes no sense as I read it back to myself :(

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions