How to store large fetched dataset from postgres in Django view?

Viewed 25

When user open some Django view there is option to choose what data to load from postgres DB. After that click submit and process is started. But when data is fetched and in the same view pressed reload, then all process starts from begining. Fetched time is about ~10min (best solution to fetched once by opening view and after that just manupulate with data without fetced each reloading)

I want to load data once or by button. But how to implement that i don't understand.

1 Answers

The easier approach is to do this with two pages:

  • First page: User can choose to load the data
  • Second page: Loads the data and shows it

If you want to do this on the same page you normally put a div on your page where the data should be loaded and then you need to use Javascript / AJAX to load and update your current page (or a part of it) based on user input like a clicked button.

There are multiple ways to implement this. Here are some examples:

I would recommend HTMX, because it allows you to do this without having to write any JavaScript and it works great together with Django templates.

Related