Hello. I have two apps. Posts and Contests.

In templates/contest/detail.html, there is a button that takes you to 
templates/post/create.html

What I want is to send the contest name from detail to create so that the 
post will be added to the right contest. For that, I guess I should do 
something to send contest name from detail.html to create view of 
post/create. Right?
In the following code (post\views.py), the contest name is determined 
randomly. Help me to get the right contest please.

if request.method == 'POST':
    items = Contest.objects.all()
    random_item = random.choice(items)
    form = PostForm(request.POST, request.FILES)

    if form.is_valid():
        post = form.save(commit = False)
        post.contest = random_item
        post.ownername = request.user
        post.save()
        messages.success(request, 'You have succesfully sent a post')
        return HttpResponseRedirect(random_item.get_absolute_url())
else:
    form = PostForm()

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/ddc3b1d3-32a3-4457-a36d-5cbbea6255b6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to