Utils

Export Data

class jmb.jadmin.utils.ExportData(modeladmin=None, queryset=None, request=None, model=None, fields_list=None)[source]

Utility to export data from a model. It can export data from model fields, model methods, model properties, model admin methods.

For a more precise export of data inside models, it’s possible to extend this class. The default get_data() will parse also methods inside of the export class, enabling the creation of export-specif fields.

It can export the data in different file output: csv, xls, xlsx.

To do so, it uses different packages:
  1. unicodecsv for .CSV
  2. xlwt for .XLS
  3. openpyxl for .XLSX.

JAdmin is NOT dependent from any of these packages. To enable the export in a specific format, it’s necessary to install one or more of these packages. In case unicodecsv is not installed, the function will try to export data using the default csv python package, which cannot, however, grant data integrity in case of unicode strings. In the other two cases, the export won’t work, returning an ImportError.

Whenever any of the packages is installed, the corresponding action will get enabled into the admin extra_action_form.

Parameters:
  • modeladmin – the modeladmin.
  • request – the request, not used
  • queryset – the queryset or a list of
  • model – the model (used to export directly from model).
  • fields_list – the list of fields to be exported

Previous page

← Extra action form

Next page

→ Changelog

This Page