il_doc 14 Newbie Poster

I'm making a simple blog and I've some problems with post/tag relationship:
when i create a post, i want to be able to choose through existing tags and/or create new ones (I'm using select2.js)

My view is:

def add_post(request):
    if request.method == 'POST':
        form = PostForm(data=request.POST)
        if form.is_valid():
            model_instance = form.save(commit=False)
            model_instance.author = request.user
            model_instance.save()

            # this isn't working as expected #
            for tag in model_instance.tags.all():
                t = Tag.objects.get_or_create(
                        author=request.user, 
                        title=tag.title, 
                        slug=slugify(tag.title)
                    )
                model_instance.tags.add(t)
            ##################################

            return HttpResponseRedirect("/blog/")
    else:
        form = PostForm()
    return render_to_response(
        'blog/add_post.html',
        {'form' : form },
        context_instance=RequestContext(request))

I'm not sure about how to handle on-the-fly tags...
Any help? :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.