django-commons / drf-excel

An XLSX spreadsheet renderer for Django REST Framework.
BSD 3-Clause "New" or "Revised" License
217 stars 40 forks source link

Global date/time formats #49

Closed rptmat57 closed 2 years ago

rptmat57 commented 2 years ago

I was wondering if it would be possible to have global date/time formats, to be set in settings.py similar to both django and django rest framework formats: DATETIME_FORMAT, DATE_FORMAT, TIME_FORMAT

The reason is that the django rest framework API is more meant to be accessed programmatically, and for that the date format makes sense to be ISO format (standard, easier to parse etc. in many languages)

However, XLSX is meant to be human readable, and ISO format just doesn't make much sense in that regard. Considering dates are stored in UTC a lot, this makes it confusing in Excel and Excel itself doesn't deal with ISO formats.

willtho89 commented 2 years ago

currently its possible to set the date formating on a per field basis per ViewSet. e.g.

class MyViewSet(XLSXFileMixin, viewsets.ReadOnlyModelViewSet):
    xlsx_date_format_mappings = {
        'created_at': '%d.%m.%Y %H:%M', 
        'date': '%d.%m.%Y',
    }

I'm open to having it set globally through settings, but currently quite busy…

rptmat57 commented 2 years ago

Yes I noticed that, but it would be a lot to add it for every date field for every model.

I am glad you are open to it, I'll look into it if I have some time.