tags:

views:

28

answers:

1

Hi,

I`m trying to create a message which uses some kind of pluralization. The message look like this and depends on the number of deleted objects.

Successfully deleted [number of objects] Contact(s)

Thus output can be:

Successfully deleted 1 Contact Successfully deleted 5 Contacts

To achieve this task i followed the pluralization documentation which i referenced below:

pluralization

My code in the view:

count = returned_objects.count()
    if count == 1:
        name = model._meta.verbose_name
    else:
        name = model._meta.verbose_name_plural

    text = ungettext(
         'Successfully deleted %(count)d %(name)s .',
         'Successfully deleted %(count)d %(name)s .',
         count
    ) % {
        'count': count,
        'name': name
    }
    print text

My code in the model:

class Meta:
        verbose_name = _('contact')
        verbose_name_plural = _('contacts')

The result is now "Successfully deleted 1 django.utils.functional.proxy object at 0x014D9B70"

I`m wondering why I do not get the verbose_name as output. Instead i get django.utils.functional.proxy object as the output for name.

+1  A: 

When you look at the proxy object, you'll see that it is a proxy object for a string-like class.

Try using model._meta.verbose_name_plural.title() to get a string from the proxy object.

S.Lott
Perfect! This works! I`m really impressed about stackoverflow and it`s community. So fast and reliable. Just great :-)What I`m wondering about is that why .title() in the documention, which i referenced above, is not used!?
Tom Tom