I am using ModelForm on Django 1.3.
models.py:
class UserProfile(models.Model):
...
gender = models.CharField(max_length=1, blank=True, choices=((\'M
Even without blank=True it shows the extra input. I have created a new Widget:
from itertools import chain
from django.forms import RadioSelect
from django.utils.encoding import force_unicode
class RadioSelectNotNull(RadioSelect):
def get_renderer(self, name, value, attrs=None, choices=()):
"""Returns an instance of the renderer."""
if value is None: value = ''
str_value = force_unicode(value) # Normalize to string.
final_attrs = self.build_attrs(attrs)
choices = list(chain(self.choices, choices))
if choices[0][0] == '':
choices.pop(0)
return self.renderer(name, str_value, final_attrs, choices)