Crispy shapes ignore the initial value for the switch

I am trying to conditionally set the initial value on the fragile field of the InlineRadio form, and they ignore me.

I set the value initialas follows:

class CustomWizardForm3(ModelForm):
  def __init__(self, user, *args, **kwargs):
    self.helper = FormHelper()
    self.helper.layout = Layout(
        Fieldset("",
            Div(ImageInlineRadios('sleeve_length'), css_class='span8 clearfix'),
            Div(
                CustomStyleDiv('armhole_edging_stitch', 'armhole_edging_height'),
                css_class="row-fluid")
        )
    ) 

    super(CustomWizardForm3, self).__init__(user, HELP_TEXT, *args, **kwargs)

    if self.instance.is_vest():
        self.fields['sleeve_length'].initial = DC.SLEEVE_VEST

  class Meta:
    model = IndividualDesign
    fields = ('armhole_edging_stitch', 'armhole_edging_height', 'sleeve_length',)

The model is sleeve_lengthdeclared as:

sleeve_length= models.CharField(
    max_length = 20,
    choices = DC.SLEEVE_LENGTH_CHOICES,
    null = True, 
    blank = True)

I went through it in the debugger, and the attribute is initialset to what I expect. But when the switches are generated, nothing is checked. What gives? Crispy and / or Django Forms annoy me.

ETA: ImageInlineRadios is a simple subclass of the standard crisp thing.

class ImageInlineRadios (InlineRadios):

def __init__(self, *args, **kwargs):
    self.span_class = kwargs.pop('span_class', 2)
    super(ImageInlineRadios, self).__init__(*args, **kwargs)

template = 'radio_buttons.html'

def render(self, form, form_style, context, template_pack='bootstrap'):
    import pdb; pdb.set_trace()
    context.update({'inline_class': 'inline', 
                    'images': 'none', 
                    'span_class':self.span_class})
    return super(ImageInlineRadios, self).render(form, form_style, context)

In the template file radio_buttons.html we have:

<input type="radio"
   {% if choice.0|stringformat:"s" == field.value|stringformat:"s" %} checked="checked"{% endif %} 

field.value initial? , radioselect.html, , - , , , .

+4

All Articles