I a have a django form which is a select field called piece which will be populated as a ModelChoiceField:
class ProjectInfoForm(forms.Form):
module = forms.ModelChoiceField(
queryset=Module.objects.all(),
)
piece = forms.ModelChoiceField(
queryset=Piece.objects.all(),
)
I initially had this as above where the field loaded up all the piece objects initially. However, this is uneccessary as the piece field is populated via ajax depending on what the user selects for module.
My question is, what is the best way to initalize this piece field as a blank select field, with maybe one empty label, along the lines of ‘——–‘?
Any help much appreciated.
For the
-------option just make it an optional field withrequired=Falseand to start with no choices use an empty queryset withPiece.objects.none():