Replace dashes in empty drop down item (ModelChoiceField)

Hello! I’m still pretty new to Django, and would like to replace the default “-------” in a ModelChoiceField in a ModelForm. The docs state I need to set the empty_label attribute.

However, I’m having trouble figuring out how to write the required queryset argument. Here is my code so far…

Model

class InternalExternal(models.TextChoices):
    INTERNAL = "internal"
    EXTERNAL = "external"

class Clients(models.Model):
    internal_external = models.CharField(
        "internal/external group",
        choices=InternalExternal.choices,
        help_text="A group is either internal or external to your organization",
        max_length=25,
    )

Model Form

class FooCreateForm(ModelForm):
    internal_external = ModelChoiceField(queryset=Clients.objects.???, empty_label="select a value")
    class Meta:
        fields = ("internal_external")
        model = Clients

I’ve tried numerous things, but I can’t figure out what to plug in as a queryset to (essentially) provide the contents of my InternalExternal class. I’m very new to Querysets, and the surface area of the AP is rather immense!

Additionally, is there a good (clean) way to replace the “-----” items for all the ModelChoiceFields in my project (an override of some sort)? Any help would be greatly appreciated!

Selecting from a TextChoices class is not a ModelChoiceField. That field is used when you’re trying to set a foreign key value to the instance of a class.

See the example at enumeration types for an example of how a TextChoices class is used.

1 Like

Thank you for your very helpful and kindly answer. We’re all very grateful for your time and expertise on these forums! I feel rather silly after reading your response. I read over the documentation for the ModelChoicesField many times, but somehow overlooked the bit about it being only for queries (foreign keys, etc.)