{{{
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.
* 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>
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>
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>
* 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>
* status: assigned => closed
* resolution: => fixed
Comment:
Fixed in eb901681ab58c008f7bbbe555e5f43f8e0893bd3 and
b93fb3d6be944bd196a6a7be576f0622c4e3f59c.
--
Ticket URL: <https://code.djangoproject.com/ticket/33398#comment:5>