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

  • Home
  • SEARCH
  • 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 7840773
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T15:54:47+00:00 2026-06-02T15:54:47+00:00

I have a ModelForm that contains a ModelChoiceField using the RadioSelect widget. class MyAForm(forms.ModelForm):

  • 0

I have a ModelForm that contains a ModelChoiceField using the RadioSelect widget.

class MyAForm(forms.ModelForm):
    one_property = models.ModelChoiceField(
        widget=forms.RadioSelect,
        queryset=MyBModel.objects.filter(visible=True),
        empty_label=None)
    class Meta:
        model = MyAModel

There are attributes on MyBModel that I want to display next to the radio button. I would override label_from_instance on a sub-class of ModelChoiceField but this does not allow me to do what I want as I want the radio button to appear inside a table which has a row for each selection item.

So somewhere in my template I want something like…

{% for field in form.visible_fields %}
    {% if field.name == "one_property" %}
    <table>
        {% for choice in field.choices %}
            <tr>
                <td><input value="{{choice.id}}" type="radio" name="one_property" />{{choice.description}}</td>
                <td><img src="{{choice.img_url}}" /></td>
            </tr>
        {% endfor %}
    </table>
    {% endif %}
{% endfor %}

Unfortunately field.choices returns a tuple of the object’s id and the label and not an instance from the queryset.

Is there a simple way to get instances of the choices for a ModelChoiceField to use within a template?

  • 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-02T15:54:48+00:00Added an answer on June 2, 2026 at 3:54 pm

    After delving into the django source for ModelChoiceField I discovered it has a property “queryset”.

    I was able to use something like…

    {% for field in form.visible_fields %}
        {% if field.name == "one_property" %}
        <table>
            {% for choice in field.queryset %}
                <tr>
                    <td><input value="{{choice.id}}" type="radio" name="one_property" />{{choice.description}}</td>
                    <td><img src="{{choice.img_url}}" /></td>
                </tr>
            {% endfor %}
        </table>
        {% endif %}
    {% endfor %}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a form class that looks like this: class ApplicationDetailsForm(ModelForm): worked_in_industry = forms.TypedChoiceField(coerce=int,
I have the following model and it's form: class Project(models.Model) class ProjectForm(forms.ModelForm) class Meta:
I have a ModelForm field that is based on the following Model: class Phrase(models.Model):
I have a simple form that looks like this: class SettingsForm(forms.ModelForm): theme = forms.CharField(required=True,
I have a form in Django that looks like this class FooForm(forms.ModelForm): foo_field =
I have a Model that looks like: class MyModel(Model): name = models.TextField(blank=True, default='') bio
I have a django model that I'm displaying as a form using a ModelForm.
I have a model that looks like this class RSVP (models.Model): def __unicode__(self): return
I have a ModelForm in my Django app that uses a forms.ModelMultipleChoiceField, which displays
I have a simple model that is defined as: class Article(models.Model): slug = models.SlugField(max_length=50,

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.