Search code examples
djangodjango-admin

Dynamic verbose name of model in Django Admin


I have a HelpTicket model, and I want the main Django admin page to show the Verbose Name as HelpTickets (2 unclosed) where HelpTicket.objects.count(closed=False) = 2

Is there an easy way of dynamically over-riding the verbose name in this fashion?

enter image description here


Solution

  • You can use proxy model here.

    class ShowHelpTicket(HelpTicket):
        class Meta:
            proxy = True
            verbose_name_plural = "Help Tickets ( " + str(HelpTicket.objects.count(closed=False)) + "unclosed )"
    

    Here you'll find a nice tutorial. Using Proxy Models to Customize the Django Admin