def formfield_for_foreignkey(self, db_field, *args, **kwargs):
if db_field.name == 'myfield':
kwargs['empty_label'] = "I WANT TO SET MY OWN EMPTY LABEL"
return super().formfield_for_foreignkey(db_field, *args, **kwargs)
}}}
You get never the "I WANT TO SET MY OWN EMPTY LABEL"
How to fix it:
In django\contrib\admin\options.py, row 234:
{{{
kwargs['empty_label'] = _('None') if db_field.blank else None
}}}
Should be changed on:
{{{
kwargs['empty_label'] = (kwargs.get('empty_label') or _('None')) if
db_field.blank else None
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/33524>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* has_patch: 1 => 0
* type: Bug => New feature
* stage: Unreviewed => Accepted
Comment:
Agreed, `empty_label` from `kwargs` should take precedence over
`_('None')`.
--
Ticket URL: <https://code.djangoproject.com/ticket/33524#comment:1>
Comment (by revanthgss):
Can I work on this? I want to get familiarised with the contributing
process so that I can contribute larger features in future.
--
Ticket URL: <https://code.djangoproject.com/ticket/33524#comment:2>
* owner: nobody => revanthgss
* status: new => assigned
--
Ticket URL: <https://code.djangoproject.com/ticket/33524#comment:3>
* owner: revanthgss => Hrushikesh Vaidya
* has_patch: 0 => 1
Comment:
Hey revanthgss, since we haven't heard from you in a while, I'm assigning
this to myself :)
[https://github.com/django/django/pull/15467 PR]
--
Ticket URL: <https://code.djangoproject.com/ticket/33524#comment:4>
Comment (by revanthgss):
Replying to [comment:4 Hrushikesh Vaidya]:
> Hey revanthgss, since we haven't heard from you in a while, I'm
assigning this to myself :)
> [https://github.com/django/django/pull/15467 PR]
Sorry, I did not get time to check it out. All the best!!
--
Ticket URL: <https://code.djangoproject.com/ticket/33524#comment:5>
* status: assigned => closed
* resolution: => fixed
Comment:
In [changeset:"119f227aa62885f12cd7dd2558a62148d02adbb4" 119f227]:
{{{
#!CommitTicketReference repository=""
revision="119f227aa62885f12cd7dd2558a62148d02adbb4"
Fixed #33524 -- Allowed overriding empty_label for ForeignKey in
ModelAdmin.radio_fields.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/33524#comment:8>
* needs_tests: 1 => 0
* stage: Accepted => Ready for checkin
--
Ticket URL: <https://code.djangoproject.com/ticket/33524#comment:7>