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 6388519
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T03:17:19+00:00 2026-05-25T03:17:19+00:00

I have a form (edited for brevity) as follows: class InteractionForm(forms.Form): def __init__(self, *args,

  • 0

I have a form (edited for brevity) as follows:

class InteractionForm(forms.Form):
    def __init__(self, *args, **kwargs):

        # Each object within this queryset is a model object of type InteractionChoice
        choices_qs = interaction.interactionchoice_set.all()

        self.fields['choices'] = forms.ModelChoiceField(
                                    widget=forms.RadioSelect(),
                                    queryset=choices_qs,

The InteractionChoice model looks like:

class InteractionChoice(models.Model):
    interaction = models.ForeignKey(Interaction)
    name = models.CharField(max_length=255)
    is_answer = models.BooleanField(default=False)

An instance of InteractionForm is passed from a view to a template and rendered via:

{{ form.choices }}

My question is whether there is a way to iterate over each choice in my template and access one of its properties — specifically, the is_answer property defined in InteractionChoice. The purpose being to customize how a choice is displayed if it is indeed the answer. More specifically, if is_answer is True, I’d possibly change the class attribute on the <label> for that choice.

Perhaps, I’m approaching this problem from the wrong direction. If anyone has pointers for alternative ideas, I’d be happy to hear them.

Thanks in advance.

Update 1:
Thinking about this more after @rczajka’s response, I don’t believe I can achieve what I’m hoping to do in the template code. Instead, if the purpose is to modify the tag’s class attribute, I should perhaps be looking to subclass and override certain methods in forms.widgets.RadioInput, forms.widgets.RadioFieldRenderer, and forms.widgets.RadioSelect. I’ll dig into this more.

  • 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-05-25T03:17:20+00:00Added an answer on May 25, 2026 at 3:17 am

    I came up with one solution that addresses this problem. It’s hackish, to say the least, but it’s the only approach I’ve thought of that works thus far without a lot of back-end changes to my existing design.

    My approach stemmed from this article on subclassing `RadioFieldRenderer’ and ‘RadioSelect’.

    In the __unicode__ method for an InteractionChoice model, I return:

    return self.name + "_" + str(self.is_answer)
    

    which is the value used for a radio button’s label (amongst other things). I then subclassed forms.widgets.RadioInput, forms.widgets.RadioFieldRenderer, and forms.widgets.RadioSelect.

    For the custom RadioInput class, I overrode its __unicode__ method to include logic to append a class string – whose value is ultimately dictated by the string returned from the unicode method in InteractionChoice – to the <label> tag string it returns.

    For the custom RadioFieldRenderer class, I overrode __iter__ and __getitem__ to use the custom RadioInput class.

    For the custom RadioSelect class, I overrode the renderer property to use my custom radio field renderer.

    This is obviously far from an ideal solution. Hopefully, a better one will arise.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Rails form for editing objects of a particular class. The labels
I have a form that can be filled, saved, loaded and re-edited. When it
I have form area in my view. If I click button A , I
I have form that displays several keywords (standard set of choice lists that changes
I have form with user defined filters ( combobox with column names, combobox with
i have form action file in another directory but some file send to this
I have form with one input for email and two submit buttons to subscribe
I have form with 1 button. when you click on the button 3 others
I have form with few buttons and I want to know what button is
I have form where user submits field. Field can have letters, numbers, and punctuation.

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.