Search code examples
python-3.xdjangodjango-import-export

How to format export fields with numeric values in django-import-export


Using django-import-export to export data from django admin in excel xlsx format.

However, numeric fields export as text in excel.

enter image description here

I'd like to export correctly as numeric fields.

Documentation has a sample syntax for BooleanWidget, but it's not working, it replaces the value with the object __str__ value, instead of converting the value to a number.


Solution

  • Found out I have to instantiate the widget, not reference the class (Use parenthesis at the end)

    from import_export import widgets
    
    enrolled = fields.Field(widget=widgets.NumberWidget())`
    

    Created a pull request to fix sample usage.