Django – eliminate default blank options from dropdown

Model forms in Django are derived from the model itself. The dropdowns can be defaulted by passing a dictionary of defaults in the view – when the model form is initialized. But I could still see the blank options in the dropdown <select value=””>———-</select>. In order to get rid of the blanks, I had to make an accommodation in the model by setting blank = False and assigning a default value to each field.

model_status = models.IntegerField(choices=StatusTypes.get_choices(), blank = False, default = StatusTypes.DISABLED)
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s