'django admin panel healthcheck

I want to create a healthcheck endpoint for my django admin panel. I want to register it via admin.site.register_view (I am using the adminplus package) but I can't figure out how to made it accessible to the public, without the need to authenticate first.

Any ideas?



Solution 1:[1]

So I ended up overriding def has_permission(self, request) in subclass of AdminPlusMixin:

from adminplus.sites import AdminPlusMixin


class MyAdmin(AdminPlusMixin, AdminSite):

    def has_permission(self, request):
        if request.resolver_match.url_name == 'admin-healthcheck':
            return True
        return super().has_permission(request)

Solution 2:[2]

I believe that package is outdated, instead you could do something like the following:

Created a proxy model in models.py such as:

class Proxy(models.Model):

    id = models.BigAutoField(db_column='id', primary_key=True)

    def str(self):
        return "<Label: id: %d>" % self.id

    class Meta:
        managed = False
        verbose_name_plural = 'proxies'
        db_table = 'proxy'
        ordering = ('id',)

Which is just a mysql view that a created from am existing table

 create view proxy
    as select id
    from samples
    LIMIT 10;

And finally in admin.py

@admin.register(Proxy)
class LabelAdmin(admin.ModelAdmin):
    change_list_template = 'label_view.html'
    def changelist_view(self, request, extra_context=None):
      ...
        return render(request, "label_view.html", context)

This way it will show in the admin panel, inside the app you're working on.

Probably what you have is a function in your views.py, in this case you should replace that function content where the "..." are in the LabelAdmin class.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 marke
Solution 2 Mr Quenonoscaguen