Extra_context not changing dynamically

I added extra_context on the admin url and display them in the admin index page. but they do not dynamically update in the template even if I refresh the page. I have to stop the django server and start it again before it updates

orders = Order.objects.all().count()
shippings = Shipping.objects.all().count()
stores = Store.objects.all().count()
users = User.objects.all().count()

path(‘admin/’, admin.site.urls, {‘extra_context’ : {‘orders’: orders, ‘shippings’:shippings, ‘stores’:stores, ‘users’:users }}),

Instead of passing dynamic values in the URL extra_context, Try to override ModelAdmin.
Refer :smile: Docs

class MyModelAdmin(admin.ModelAdmin):

    # A template for a very customized change view:
    change_form_template = 'admin/myapp/extras/openstreetmap_change_form.html'

    def get_osm_info(self):
        # ...
        pass

    def change_view(self, request, object_id, form_url='', extra_context=None):
        extra_context = extra_context or {}
        extra_context['osm_data'] = self.get_osm_info()
        return super().change_view(
            request, object_id, form_url, extra_context=extra_context,
        )

Thanks for this. but could you please be explicit on how add extra context on the index view?

my aim is to have a dashboard that will show some statistics from various models of the system