[Django] #33524: ModelAdmin with defined radio_fields override empty_label

4 views
Skip to first unread message

Django

unread,
Feb 18, 2022, 8:44:02 AM2/18/22
to django-...@googlegroups.com
#33524: ModelAdmin with defined radio_fields override empty_label
-------------------------------------+-------------------------------------
Reporter: Maxim | Owner: nobody
Danilov |
Type: Bug | Status: new
Component: | Version: 4.0
contrib.admin | Keywords: modeladmin,
Severity: Normal | radio_fields, empty_label
Triage Stage: | Has patch: 1
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 1
UI/UX: 0 |
-------------------------------------+-------------------------------------
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
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/33524>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Feb 18, 2022, 1:25:21 PM2/18/22
to django-...@googlegroups.com
#33524: ModelAdmin with defined radio_fields override empty_label
-------------------------------------+-------------------------------------
Reporter: Maxim Danilov | Owner: nobody
Type: New feature | Status: new
Component: contrib.admin | Version: 4.0
Severity: Normal | Resolution:
Keywords: modeladmin, | Triage Stage: Accepted
radio_fields, empty_label |
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* 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>

Django

unread,
Feb 19, 2022, 4:34:47 AM2/19/22
to django-...@googlegroups.com
#33524: ModelAdmin with defined radio_fields override empty_label
-------------------------------------+-------------------------------------
Reporter: Maxim Danilov | Owner: nobody
Type: New feature | Status: new
Component: contrib.admin | Version: 4.0
Severity: Normal | Resolution:
Keywords: modeladmin, | Triage Stage: Accepted
radio_fields, empty_label |
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------

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>

Django

unread,
Feb 19, 2022, 8:19:30 AM2/19/22
to django-...@googlegroups.com
#33524: ModelAdmin with defined radio_fields override empty_label
-------------------------------------+-------------------------------------
Reporter: Maxim Danilov | Owner:
| revanthgss
Type: New feature | Status: assigned

Component: contrib.admin | Version: 4.0
Severity: Normal | Resolution:
Keywords: modeladmin, | Triage Stage: Accepted
radio_fields, empty_label |
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by revanthgss):

* owner: nobody => revanthgss
* status: new => assigned


--
Ticket URL: <https://code.djangoproject.com/ticket/33524#comment:3>

Django

unread,
Feb 26, 2022, 10:04:59 PM2/26/22
to django-...@googlegroups.com
#33524: ModelAdmin with defined radio_fields override empty_label
-------------------------------------+-------------------------------------
Reporter: Maxim Danilov | Owner:
| Hrushikesh Vaidya

Type: New feature | Status: assigned
Component: contrib.admin | Version: 4.0
Severity: Normal | Resolution:
Keywords: modeladmin, | Triage Stage: Accepted
radio_fields, empty_label |
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Hrushikesh Vaidya):

* 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>

Django

unread,
Feb 27, 2022, 3:31:20 AM2/27/22
to django-...@googlegroups.com
#33524: ModelAdmin with defined radio_fields override empty_label
-------------------------------------+-------------------------------------
Reporter: Maxim Danilov | Owner:
| Hrushikesh Vaidya
Type: New feature | Status: assigned
Component: contrib.admin | Version: 4.0
Severity: Normal | Resolution:
Keywords: modeladmin, | Triage Stage: Accepted
radio_fields, empty_label |
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------

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>

Django

unread,
Mar 5, 2022, 6:26:50 AM3/5/22
to django-...@googlegroups.com
#33524: ModelAdmin with defined radio_fields override empty_label
-------------------------------------+-------------------------------------
Reporter: Maxim Danilov | Owner:
| Hrushikesh Vaidya
Type: New feature | Status: closed
Component: contrib.admin | Version: 4.0
Severity: Normal | Resolution: fixed
Keywords: modeladmin, | Triage Stage: Ready for
radio_fields, empty_label | checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak <felisiak.mariusz@…>):

* 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>

Django

unread,
Mar 5, 2022, 6:26:52 AM3/5/22
to django-...@googlegroups.com
#33524: ModelAdmin with defined radio_fields override empty_label
-------------------------------------+-------------------------------------
Reporter: Maxim Danilov | Owner:
| Hrushikesh Vaidya
Type: New feature | Status: assigned

Component: contrib.admin | Version: 4.0
Severity: Normal | Resolution:
Keywords: modeladmin, | Triage Stage: Ready for
radio_fields, empty_label | checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* needs_tests: 1 => 0
* stage: Accepted => Ready for checkin


--
Ticket URL: <https://code.djangoproject.com/ticket/33524#comment:7>

Reply all
Reply to author
Forward
0 new messages