Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8606175
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T03:01:47+00:00 2026-06-12T03:01:47+00:00

Here is what I have, a simple Django form class survey (forms.Form): answer =

  • 0

Here is what I have, a simple Django form

class survey (forms.Form):
    answer = forms.ChoiceField(
                                 widget = RadioSelect(),
                                 choices = answers_select
                                )

Now, on my HTML page, I got not just one question but many! Is it possible to use the above answer field for all the questions? For all the questions, its just the same choices I have to show!

Say I have 3 questions:

  1. How is my restaurant
  2. How is the food
  3. How is the service

choices for the above answer field are 1. good, 2. bad 3. worst
So, I don’t want to create 3 form fields for the 3 questions as its redundant

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T03:01:48+00:00Added an answer on June 12, 2026 at 3:01 am

    Step back and think it clearly through–you’ll need 3 ChoiceField to track the answer for 3 separate questions and there’s no way around it.

    What would be redundant is to actually repeat the form field construction call, especially if you were dealing with, say, 20 questions. In this case, rather than statically constructing those fields, you can store the list of questions as a class invariant and create the form fields dynamically during the forms construction.

    Here’s something to give you a starting idea on how you might go about doing it:

    class SurveyForm(forms.Form):
        questions = _create_questions('How is my restaurant?',
                                      'How is the Food?',
                                      'How is the service?')
    
        def __init__(self, *args, **kwargs):
            # Create the form as usual
            super(SurveyForm, self).__init__(*args, **kwargs)
    
            # Add custom form fields dynamically
            for question in questions:
                 self.fields[question[0]] = forms.ChoiceField(label=question[1],
                                                              widget=forms.RadioSelect(),
                                                              choices=answers_select)
        @classmethod
        def _create_questions(cls, *questions):
            return [(str(index), question) for index, question in enumerate(questions)]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple form in Django that looks like this: class SettingForm(forms.Form): theme
I have a simple form class MyForm(forms.Form): ... fieldname = forms.CharField(help_text=Some help text) I
Have a simple form (only extract fields here) but for some reason the JQserilization
I have a simple situation here. lets face html code first => <form name=geoKey
I have an ostensibly simple problem. Here is my models.py: from django.db import models
I have two simple models in my Django app. Here's what they look like:
Here I have a simple php script which displays some values from a database
I have simple algorithm that clean the whitespace from half string until end. Here
I have a simple page here to demonstrate the issue that I am seeing.
I have a simple image gallery here . All I want to do is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.