Thanks, that's a shame... So I'm now trying to do the request.POST stuff in a view instead. Since the idea is to have the voting app as decoupled as possible, is there a slick way to pass, perhaps the whole object in this case, but at least the name of the model or similar together with the post?
Thanks! /Martin On May 13, 2:33 pm, Daniel Roseman <dan...@roseman.org.uk> wrote: > On May 13, 1:21 pm, marty3d <martin.kjellb...@gmail.com> wrote: > > > > > Hi! > > > I'm making this small generic voting application and have stumbled > > across a strange issue. > > My idea is that the user comes to a page, like /news/slug where I'm > > having an inclusion tag showing up/down voting controls. Select your > > choice in the vote form and submit. The inclusion tag then takes the > > object and saves it in the generic model, and lastly, return the user > > to the same page. > > > Everything is ok when doing a GET on the page. But after the POST, it > > doesn't seem to redirect to the page again. > > > The voting controls are in an inclusion tag, like this: > > > @register.inclusion_tag('mvote/vote_controls2.html', takes_context = > > True) > > def vote_controls(context, object): > > request = context['request'] > > item_type = ContentType.objects.get_for_model(object) > > votes = Vote.objects.filter(content_type__pk=item_type.id, > > object_id=object.pk) > > no_of_votes = object.votes.count() > > sum_of_votes = votes.aggregate(Sum('vote')) > > > if request.method == 'POST': > > form = VoteForm(request.POST) > > if form.is_valid(): > > new_vote = form.save(commit=False) > > new_vote.object_id = object.pk > > new_vote.content_type = item_type > > new_vote.save() > > return HttpResponseRedirect(request.path) > > else: > > form = VoteForm() > > > return { > > 'votes': votes, > > 'no_of_votes': no_of_votes, > > 'sum_of_votes': sum_of_votes['vote__sum'], > > 'form': form, > > } > > > Any ideas would be utterly appreciated! > > > Thanks, > > /Martin > > You can't do a redirect inside a tag. The tag doesn't have control > over the response - it is just responsible for rendering a part of the > page content. You'll need to do this in the view. > -- > DR. > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To post to this group, send email to django-us...@googlegroups.com. > To unsubscribe from this group, send email to > django-users+unsubscr...@googlegroups.com. > For more options, visit this group > athttp://groups.google.com/group/django-users?hl=en. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.