views:

51

answers:

3

Hi,

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 it?

+1  A: 

You need to use ModelChoiceField's empty_label.

celopes
Ok, thanks.But I wanna do it in some forms of admin site. I don't know how I could get a specific field of a specific form using django admin.
Maurício Okuyama
What Dmitry told you. :-)
celopes
+3  A: 

Create custom ModelForm and override your field there, then, assign this form class to form option of ModelAdmin. Like this:

#forms.py
class CustomForm(forms.ModelForm):
    user = forms.ModelChoiceField(queryset=User.objects.all(), empty_label=u'label')

class Meta:
    model = MyModel

#admin.py
class MyModelAdmin(admin.ModelAdmin):
     form = CustomForm
Dmitry Shevchenko
A: 

Thank you, guys!