Home > OS >  Best practice to read and filter a big CSV file in Django
Best practice to read and filter a big CSV file in Django

Time:07-08

I'm researching the way to read a big CSV file and display it as a datatable in Django admin. I need the filter function as well. Could anyone suggest to me which library to support?

CodePudding user response:

to read csv and convert it into Objects of Django you can use Pandas, NymPy or You can use Django itself, see CSV Serializer csv python module. https://docs.djangoproject.com/en/4.0/ref/settings/#serialization-modules

After that you receive a list of objects.

List of objects you can show in admin panel with Own view (GCBV Django, ListView) or you can override ModelAdmin to work with list of objects istead of queryset.

If you want to filter it, also you can use SimpleAdminFilter, and on POST you can filter your objects. https://docs.djangoproject.com/en/dev/ref/contrib/admin/filters/

Perhaps pandas could help you, or you can write your own sort algorithm.

If you need a speed, probably, import in temporary table in database can be better.https://www.sqlitetutorial.net/sqlite-import-csv/

This ask don't have a best practice without business-context.

  • Related