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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T12:00:00+00:00 2026-05-18T12:00:00+00:00

Suppose I created a django form that has a radio box selection in it:

  • 0

Suppose I created a django form that has a radio box selection in it:

class PlaylistsForm(forms.Form):
    choices=forms.ChoiceField( widget=forms.RadioSelect(), CHOICES,label="choices")

If I try to instantiate the form and do form.choices I get an error that the instance has no attribute choices. Can you refer me to somewhere where it explains the magic behind the creation of the fields, and secondly, how can I access the fields?

EDIT:
To make it clear: I want to know why, given an instance of PlaylistsForm, doing
print form.choices I get an error saying there’s no such attribute. What dark magic is happening behind the scenes here?

  • 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-18T12:00:00+00:00Added an answer on May 18, 2026 at 12:00 pm

    Presuming CHOICES is a tuple of options for the field, the change is relatively simple:

    class PlaylistsForm(forms.Form):
        choices=forms.ChoiceField(widget=forms.RadioSelect(),
                                  choices=CHOICES,
                                  label="choices")
    

    See the documentation of ChoiceField, and the documentation of choices for more detail.

    Changes post your edit:

    Short answer

    You’re probably confusing your field called choices, and the attribute choices on your choices field.

    Say you’ve got a form:

    my_form = PlaylistsForm()
    

    You could access the choices attribute of the choices field like this:

    my_form.fields['choices'].choices
    

    Long answer

    I didn’t know how to do what you wanted, so I stuck a import pdb; pdb.set_trace() just after I declared a form, like this:

    form = PlaylistsForm()
    import pdb; pdb.set_trace()
    

    Then, using the development server, I opened up a URL which mapped to the view with my new import pdb; pdb.set_trace() in it. Switching over to my command prompt, I could inspect what attributes and methods existed on my form object at the debug prompt:

    (Pdb) dir(form)
    

    This showed me form had a fields attribute, so I looked at it:

    (Pdb) form.fields
    

    This showed me form.fields is a dict, with values being Field objects, I picked out the choices field, and looked to see what attributes it had:

     (Pdb) dir(form.fields['choices'])
    

    This showed me that form.fields['choices'] had a choices attribute:

    (Pdb) form.fields['chiices'].choices
    [('', '---------'), (1L, My Playlist')]
    

    This is probably what you’re looking for.

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

Sidebar

Related Questions

Suppose I want to create a set of observers based on type. That is
Suppose I have a stored procedure that manages its own transaction CREATE PROCEDURE theProc
I'd like the login form (AuthenticationForm from django.contrib.auth) to appear on every page in
Suppose I have a model: class SomeModel(models.Model): id = models.AutoField(primary_key=True) a = models.CharField(max_length=10) b
I've created a custom Manager for a Django model which returns a QuerySet holding
I have a project written in Django. All fields that are supposed to store
suppose you save data into a dynamic hidden field ,which is created dynamically during
Suppose we have a package called com.example1 containing a Hello class (along with other
I've created some classes that will be used to provide data to stored procedures
Suppose you create a generic Object variable and assign it to a specific instance.

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.