Opened 3 years ago
Closed 3 years ago
#33524 closed New feature (fixed)
ModelAdmin with defined radio_fields override empty_label
Reported by: | Maxim Danilov | Owned by: | Hrushikesh Vaidya |
---|---|---|---|
Component: | contrib.admin | Version: | 4.0 |
Severity: | Normal | Keywords: | modeladmin, radio_fields, empty_label |
Cc: | Triage Stage: | Ready for checkin | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | yes | UI/UX: | no |
Description
ModelAdmin drops my "empty_label" and set "default_empty_label". For example:
class MyModelAdmin(ModelAdmin): radio_fields = 'myfield', 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
Change History (8)
comment:1 by , 3 years ago
Has patch: | unset |
---|---|
Triage Stage: | Unreviewed → Accepted |
Type: | Bug → New feature |
comment:2 by , 3 years ago
I want to work on this to get familiarised with contributing process. Assigning this to me.
comment:3 by , 3 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
follow-up: 5 comment:4 by , 3 years ago
Has patch: | set |
---|---|
Owner: | changed from | to
Hey revanthgss, since we haven't heard from you in a while, I'm assigning this to myself :)
PR
comment:5 by , 3 years ago
Replying to Hrushikesh Vaidya:
Hey revanthgss, since we haven't heard from you in a while, I'm assigning this to myself :)
PR
Sorry, I did not get time to check it out. All the best!!
comment:6 by , 3 years ago
Needs tests: | set |
---|
comment:7 by , 3 years ago
Needs tests: | unset |
---|---|
Triage Stage: | Accepted → Ready for checkin |
Agreed,
empty_label
fromkwargs
should take precedence over_('None')
.