On Sep 20, 11:54 am, Julian <maili...@julianmoritz.de> wrote: > Hi, > > I want to display a customized table for a model in the admin. I've > just written a customized filter, which works very well. > > The problem: My model has a field 'timestamp' which is a > datetimefield. It may be null, so in the admin it's displayed as > '(None)'. I want to replace '(None)' with 'All'. The problems: > > - In change_list.html the table is not generated. It's generated in > change_list_results.html. Well, the first one may be put in myapp/ > templates/myapp/mymodel/ and overwrites the default one. The latter > one not. > - So I have to write a custom template tag, which uses 'admin/ > templatetags/admin_list/result_list', just to tell it which custom > template to use. > - Then I realize that the whole > > <td class="nowrap">(None)</td> > > is NOT generated in a template but anywhere deep down in some python > code. It's not that there's a > > {% if not result.value %} > <td class="nowrap">(None)</td> > {% endif %} > > which I could replace with > > {% if not result.value %} > <td class="nowrap">All</td> > {% endif %} > > (or similar), but it seems I have to write my own customized > items_for_result-function, which just replaces with the > EMPTY_CHANGELIST_VALUE (it's '(None)') with 'All'. > > so now my final question: Isn't there an easy, not-hurting way to > solve my problem?
Instead of specifying the field name in `list_display`, specify the name of a custom method on your ModelAdmin subclass. Then define that method to return the format you want: list_display = ('name', 'my_custom_timestamp') def my_custom_timestamp(self, obj): if obj.timestamp is None: return 'All' else: return obj.timestamp -- DR. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.