Changing Foreignkey's Defaults In Admin Site
I'd like to know how I can change the blank value of ForeignKey in admin site's forms. There blank is showed as '-----'. I wanna replace it by a word. Does someone know how to do i
Solution 1:
Create custom ModelForm and override your field there, then, assign this form class to form option of ModelAdmin. Like this:
#forms.pyclassCustomForm(forms.ModelForm):
user = forms.ModelChoiceField(queryset=User.objects.all(), empty_label=u'label')
classMeta:
model = MyModel
#admin.pyclassMyModelAdmin(admin.ModelAdmin):
form = CustomForm
Solution 2:
You need to use ModelChoiceField's empty_label.
Post a Comment for "Changing Foreignkey's Defaults In Admin Site"