[Django] #33398: ModelAdmin.empty_value_display documentation

17 views
Skip to first unread message

Django

unread,
Dec 29, 2021, 4:28:11 PM12/29/21
to django-...@googlegroups.com
#33398: ModelAdmin.empty_value_display documentation
-----------------------------------------+------------------------
Reporter: Michael | Owner: nobody
Type: Bug | Status: new
Component: Documentation | Version: 4.0
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 1
UI/UX: 0 |
-----------------------------------------+------------------------
Firstly, the documentation is great. In the
[https://docs.djangoproject.com/en/4.0/ref/contrib/admin/#django.contrib.admin.ModelAdmin.empty_value_display
admin site docs], it has this example:

{{{
from django.contrib import admin

class AuthorAdmin(admin.ModelAdmin):
fields = ('name', 'title', 'view_birth_date')

@admin.display(empty_value='???')
def view_birth_date(self, obj):
return obj.birth_date]
}}}

I think this will only work for the list display, not setting the empty
value of the field during edit view.
Hence I think
{{{
fields = ('name', 'title', 'view_birth_date')
}}}
should become
{{{
list_display = ('name', 'title', 'view_birth_date')
}}}

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

Django

unread,
Dec 30, 2021, 12:27:46 AM12/30/21
to django-...@googlegroups.com
#33398: ModelAdmin.empty_value_display example in docs should use list_display.
--------------------------------------+------------------------------------
Reporter: Michael | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: Documentation | Version: 4.0
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted

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

* type: Bug => Cleanup/optimization
* stage: Unreviewed => Accepted


Comment:

> I think this will only work for the list display, not setting the empty
value of the field during edit view.

It also works for `readonly_fields`, but I agree that `list_display` fits
better here. Would you like to provide a patch?

--
Ticket URL: <https://code.djangoproject.com/ticket/33398#comment:1>

Django

unread,
Dec 30, 2021, 4:00:44 AM12/30/21
to django-...@googlegroups.com
#33398: ModelAdmin.empty_value_display example in docs should use list_display.
--------------------------------------+------------------------------------
Reporter: Michael | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: Documentation | Version: 4.0

Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
--------------------------------------+------------------------------------

Comment (by Michael):

Sure I will create a patch, before I submit it, would you please review
the following, because I am not 100% sure I understand how the readonly
functionality works for the `empty_value`:

Change from:
{{{

You can also override ``empty_value_display`` for all admin pages with
:attr:`AdminSite.empty_value_display`, or for specific fields like
this::

from django.contrib import admin

class AuthorAdmin(admin.ModelAdmin):
fields = ('name', 'title', 'view_birth_date')

@admin.display(empty_value='???')
def view_birth_date(self, obj):
return obj.birth_date
}}}

To:

{{{
You can also override ``empty_value_display`` for all admin pages with
:attr:`AdminSite.empty_value_display`.

To override just a specific ``list_display`` field, or one of the
``readonly_fields``, one can do so like this::

from django.contrib import admin

class AuthorAdmin(admin.ModelAdmin):


list_display = ('name', 'title', 'view_birth_date')

readonly_fields = ('view_birth_date', )


fields = ('name', 'title', 'view_birth_date')

@admin.display(empty_value='???')
def view_birth_date(self, obj):
return obj.birth_date
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/33398#comment:2>

Django

unread,
Dec 30, 2021, 4:12:55 AM12/30/21
to django-...@googlegroups.com
#33398: ModelAdmin.empty_value_display example in docs should use list_display.
--------------------------------------+------------------------------------
Reporter: Michael | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: Documentation | Version: 4.0

Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
--------------------------------------+------------------------------------

Comment (by Mariusz Felisiak):

IMO it's not important to mention `readonly_fields` in
`ModelAdmin.empty_value_display` docs, it's already documented in the
`display()` decorator. I would only change `fields` to `list_display`:
{{{#!diff
diff --git a/docs/ref/contrib/admin/index.txt
b/docs/ref/contrib/admin/index.txt
index 7b97ee5638..4449afaaa6 100644
--- a/docs/ref/contrib/admin/index.txt
+++ b/docs/ref/contrib/admin/index.txt
@@ -249,7 +249,7 @@ subclass::
from django.contrib import admin

class AuthorAdmin(admin.ModelAdmin):
- fields = ('name', 'title', 'view_birth_date')
+ list_display = ('name', 'title', 'view_birth_date')

@admin.display(empty_value='???')
def view_birth_date(self, obj):
}}}

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

Django

unread,
Dec 30, 2021, 4:56:13 AM12/30/21
to django-...@googlegroups.com
#33398: ModelAdmin.empty_value_display example in docs should use list_display.
-------------------------------------+-------------------------------------
Reporter: Michael | Owner: Michael
Type: | Status: assigned
Cleanup/optimization |
Component: Documentation | Version: 4.0
Severity: Normal | Resolution:
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

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

* owner: nobody => Michael
* status: new => assigned
* has_patch: 0 => 1
* stage: Accepted => Ready for checkin


Comment:

[https://github.com/django/django/pull/15259 PR]

--
Ticket URL: <https://code.djangoproject.com/ticket/33398#comment:4>

Django

unread,
Dec 30, 2021, 5:42:03 AM12/30/21
to django-...@googlegroups.com
#33398: ModelAdmin.empty_value_display example in docs should use list_display.
-------------------------------------+-------------------------------------
Reporter: Michael | Owner: Michael
Type: | Status: closed
Cleanup/optimization |
Component: Documentation | Version: 4.0
Severity: Normal | Resolution: fixed

Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

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

* status: assigned => closed
* resolution: => fixed


Comment:

Fixed in eb901681ab58c008f7bbbe555e5f43f8e0893bd3 and
b93fb3d6be944bd196a6a7be576f0622c4e3f59c.

--
Ticket URL: <https://code.djangoproject.com/ticket/33398#comment:5>

Reply all
Reply to author
Forward
0 new messages