I have no idea how to remove "--------" default action value in django admin.
or replace "------" with any other string ("Select Option").
Thanks..
I have no idea how to remove "--------" default action value in django admin.
or replace "------" with any other string ("Select Option").
Thanks..
You could try overriding the ModelAdmin.get_action_choices
method. However, this is an undocumented, internal method, so I wouldn't recommend changing it unless it's absolutely essential that you remove/replace the dashes.
remove default action
class YourModelAdmin(ModelAdmin):
def get_action_choices(self, request):
choices = super(DocumentAdmin, self).get_action_choices(request)
# choices is a list, just change it.
# the first is the BLANK_CHOICE_DASH
choices.pop(0)
return choices
replace with other string
class YourModelAdmin(ModelAdmin):
def get_action_choices(self, request):
default_choices = [("", "-----other string----")]
return super(DocumentAdmin, self).get_action_choices(request, default_choices)
set default action for your action, you can see my answer here https://stackoverflow.com/a/41276533/1265727
With the help of @Alasdair my issue is resolved.
I use this code in model.py and its change my default option value to "Select Options"
from django.db.models.fields import BLANK_CHOICE_DASH
BLANK_CHOICE_DASH = [("", "---------")]
def get_action_choices(self, request, default_choices=BLANK_CHOICE_DASH):
"""
Return a list of choices for use in a form object. Each choice is a
tuple (name, description).
"""
choices = [] + default_choices
for func, name, description in six.itervalues(self.get_actions(request)):
choice = (name, description % model_format_dict(self.opts))
choices.append(choice)
return choices
After some time later, i also find a solution of this problem..
You can also override empty_value_display for all admin pages with AdminSite.empty_value_display, or for specific fields like this:
from django.contrib import admin
class AuthorAdmin(admin.ModelAdmin):
fields = ('name', 'title', 'view_birth_date')
def view_birth_date(self, obj):
return obj.birth_date
view_birth_date.short_name = 'birth_date'
view_birth_date.empty_value_display = '???'