Django pluralization function .__ proxy__object instead of verbose_name

I am trying to create a message that uses some kind of pluralization. The message looks like this and depends on the number of deleted objects.

Deleted [number of objects] Contact (s)

Thus, the conclusion could be:

Successfully Deleted 1 Contact Deleted 5 Contacts

To achieve this, I followed the pluralization documentation, which I referenced below:

pluralization

My code in 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')

Now the result is β€œ1 object django.utils.functional. Proxy in 0x014D9B70 removed”

I am wondering why I do not get verbose_name as output. Instead, I get django.utils.functional. proxy object as output for the name.

+3
1

-, , - string.

model._meta.verbose_name_plural.title(), -.

+4

Source: https://habr.com/ru/post/1726890/


All Articles