tags:

views:

247

answers:

1

When making forms in Django, the IntegerField comes with a blank choice (a bunch of dashes "------") if called with blank=True and null=True. Is there any way to get ManyToManyField to include such an explicit blank choice?

I've tried subclassing ManyToManyField with no success:

class ManyFieldWithBlank(ManyToManyField):  

    """  
    A Many-to-Many Field with a blank choice  
    """  
    def get_choices_default(self):
        return Field.get_choices(self, include_blank=True)
+3  A: 

That is not really an improvement on the interface, IMO.

Why not have a button in your template saying "none of these" or "reset choices"? Better yet - if your field is called "Blah" make the button say "Unselect all Blah".

The button would just have some javascript to clear out any selection in the select box.

This is a much clearer UI for the user and easy to implement.

Disclaimer: IANADesigner.

celopes
Agreed: this is a UI issue that should be handled in JS, not via an extra selectable option.
Carl Meyer