I can't rewrite the mysite/polls form into classes.help me. I get
different errors every time.

<!-- detail.html -->
<form action="" method="post">
    {% csrf_token %}
    {{ form.as_p }}
    <input type="submit" value="Vote">
</form>

# forms.py:
from django import forms
from .models import Choice

class VoteForm(forms.ModelForm):
    choices = [(ch.pk, ch.choice_text) for ch in Choice.objects.filter(pk=pk)]
    choices = tuple(choices)
    choice_text = forms.ChoiceField(widget=forms.RadioSelect(choices=choices))
    class Meta:
        model = Choice
        fields = ['choice_text']

# views.py#
class DetailView(generic.FormView, generic.DetaildView):
    model = Question
    template_name = 'polls/detail.html'
    form_class = VoteForm
    def get_queryset(self):
        """
        Excludes any questions that aren't published yet.
        """
        return Question.objects.filter(pub_date__lte=timezone.now())

    def get_context_data(self, **kwargs):
        context = super().get_context_data(**kwargs)
        #context["pk"] = self.pk
        #context["form"] = VoteForm()
        return context

    #def get(self, request, *args, **kwargs):
        #form = VoteForm(pk=kwargs['pk'])
        #return super().get(self, request, *args, **kwargs)

How do you bind it all together? How get question_id (pk) in form, how
mix with detaild view, how correct check validation this form?

I'm confused. Help please. Is it possible?

--
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/a00fe267-6185-ed1d-e043-882eb5e4171b%40gmail.com.

Reply via email to