[Answer]-How do I add a blank default option to a select widget?

1👍

After playing around with it for a while, I discovered what I needed to do:

FIELD_ONE_CHOICES = (('', '-----'),)
for datum in my_model.objects.distinct('field_one'):
    FIELD_ONE_CHOICES += ((datum.field_one, datum.field_one),)
FIELD_TWO_CHOICES = (('', '-----'),)
for datum in my_model.objects.distinct('field_two'):
    FIELD_TWO_CHOICES += ((datum.field_two, datum.field_two),)

search_form = modelform_factory(my_model,
                                fields=('field_one', 'field_two'),
                                widgets={'field_one': Select(choices=FIELD_ONE_CHOICES),
                                         'field_two': Select(choices=FIELD_TWO_CHOICES),
                                }
)

Tuples can be frustrating…

Leave a comment