Django: Insert choice is neglected in form init -
in model, have charfield few choices:
surface_choices = ( ('as', _('asphalt')), ('co', _('concrete')), ('ot', _('other')), ) surface = models.charfield(choices = roof_surface_choices, max_length = 2, blank = true, null = true,) i avoid ------- choice in dropdown boxes in form, , replace more descriptive text.
i used following line in __init__ method of forms.py
def __init__(self, auto_id='%s', *args, **kwargs): super(surfaceupdateform, self).__init__(*args, **kwargs) self.fields['surface'].choices.insert(0,('', _('please choose surface'))) however, in current app, first line remains ------- , not replaced stated text above. there better way set blank values?
the ------- appears because field has blank=true, is, optional. django mechanics kinda hard understand, can override choices:
def __init__(self, auto_id='%s', *args, **kwargs): super(surfaceupdateform, self).__init__(*args, **kwargs) self.fields['surface'].choices = [('', _('please choose surface'))] + mymodel.surface_choices
Comments
Post a Comment