Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to auto refresh admin page on browser after data have changed on server?

I want to auto refresh the admin page on browser after a specific model on the database changes. Is it possible to do that?

To be more clearly: I want to refresh the url .../admin/restaurants/orders/ that is already opened on the browser, after the user posts a new order.

like image 592
Fernando Gallo Avatar asked Nov 15 '25 10:11

Fernando Gallo


1 Answers

You can send ajax request (do it in your custom js file) to same url == window.location.href (for example every 10 seconds)

class OrderAdmin(admin.ModelAdmin):
    class Meta:
        model = Order
    class Media:
        js = ("my_code.js",)

Useful links:

https://docs.djangoproject.com/en/dev/ref/contrib/admin/#modeladmin-asset-definitions

http://www.w3schools.com/jquery/ajax_ajax.asp

http://api.jquery.com/jquery.ajax/

like image 164
madzohan Avatar answered Nov 18 '25 12:11

madzohan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!