Opened 15 years ago

Closed 15 years ago

#12277 closed (wontfix)

Admin action example should use verbose_name in message_bit

Reported by: Alex Hayes Owned by: nobody
Component: Documentation Version: dev
Severity: Keywords: admin action
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Within http://docs.djangoproject.com/en/dev/ref/contrib/admin/actions/#actions-as-modeladmin-methods it contains the following example;

class ArticleAdmin(admin.ModelAdmin):
    ...

    def make_published(self, request, queryset):
        rows_updated = queryset.update(status='p')
        if rows_updated == 1:
            message_bit = "1 story was"
        else:
            message_bit = "%s stories were" % rows_updated
        self.message_user(request, "%s successfully marked as published." % message_bit)

However, a DRY approach would be to use the models meta verbose_name and verbose_name_plural, ie:

from django.utils.encoding import force_unicode

class ArticleAdmin(admin.ModelAdmin):
    ...

    def make_published(self, request, queryset):
        rows_updated = queryset.update(status='p')
        if rows_updated == 1:
            message_bit = "1 %s was" % force_unicode(self.model._meta.verbose_name)
        else:
            message_bit = "%s %s were" % (rows_updated, force_unicode(self.model._meta.verbose_name_plural))
        self.message_user(request, "%s successfully marked as published." % message_bit)

That is of course unless there is a better way of doing this with a method?

Change History (2)

comment:1 by Tim Graham, 15 years ago

Summary: Admin action shouldAdmin action example should use verbose_name in message_bit

comment:2 by Russell Keith-Magee, 15 years ago

Resolution: wontfix
Status: newclosed

I'm not convinced that this change improves the documentation. The purpose of documentation is to be easy to understand - this introduces an esoteric, unrelated feature for no particular reason.

Note: See TracTickets for help on using tickets.
Back to Top