i have a question on how do i get rid of the ---- from the select drop down menu not to show the null(---) in the first row. I found from stackoverflow on RadioSelect and i manage to get rid of the --- but i am stuck in the select drop down menu...:( here is my coding example.
models.py
colorradio = (("1" , 'Yellow'),
("2" , 'Red'),
("3" , 'Blue'),
("4" , 'Black'),)
COLORRADIO = models.CharField(max_length = 2, choices = colorradio, null = True, blank = True)
colorselect= (("1" , 'Yellow'),
("2" , 'Red'),
("3" , 'Blue'),
("4" , 'Black'),)
COLORSELECT= models.CharField(max_length = 2, choices = colorselect, null = True, blank = True)
forms.py
class RadioSelectNotNull(RadioSelect, Select):
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)
class RainbowForm(ModelForm):
class Meta:
model = Rainbow
widgets = {'COLORRADIO':RadioSelectNotNull(), # this is correct and NOT shown ---
'COLORSELECT':RadioSelectNotNull(), #should be in dropdown menu
}
I did like the COLORSELECT
to show as dropdown menu and also not showing the ---- in the first row. But if im using like the above code i get COLORSELECT
as RadioSelect
and NOT showing ---- (which is what i am want for not showing ---) but not as RadioSelect
.
Thank you so much in advance.