Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to get rid of the bogus choice generated by RadioSelect of Django Form
    text
    copied!<p>I am using ModelForm on Django 1.3.</p> <p>models.py:</p> <pre><code>class UserProfile(models.Model): ... gender = models.CharField(max_length=1, blank=True, choices=(('M', 'Male'), ('F', 'Female'), ('Unspecified', '')), default='M') ... </code></pre> <p>forms.py:</p> <pre><code>class UserProfileForm(ModelForm): class Meta: model = UserProfile fields = ('gender') widgets = { 'gender': forms.RadioSelect(), } </code></pre> <p>When this widget is rendered into HTML, I got</p> <pre><code>&lt;ul&gt; &lt;li&gt;&lt;label for="id_gender_0"&gt;&lt;input type="radio" id="id_gender_0" value="" name="gender" /&gt;---------&lt;/label&gt;&lt;/li&gt; &lt;li&gt;&lt;label for="id_gender_1"&gt;&lt;input checked="checked" type="radio" id="id_gender_1" value="M" name="gender" /&gt; Male&lt;/label&gt;&lt;/li&gt; &lt;li&gt;&lt;label for="id_gender_2"&gt;&lt;input type="radio" id="id_gender_2" value="F" name="gender" /&gt;Female&lt;/label&gt;&lt;/li&gt; &lt;li&gt;&lt;label for="id_gender_3"&gt;&lt;input type="radio" id="id_gender_3" value="" name="gender" /&gt; Unspecified&lt;/label&gt;&lt;/li&gt; &lt;/ul&gt; </code></pre> <p><strong>Problem:</strong> How can I get rid of the bogus choice "--------"?</p> <p>The same problem was brought up by another stackoverflow user months ago (<a href="https://stackoverflow.com/questions/3248887/how-to-render-a-django-form-with-radioselect-without-getting-a-checked-radiobutto" title="Link">Here</a>). I have tried the accepted solution in there (as you can see) but that didn't work for me. </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload