wharton / drf-excel

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

The problem that cann't export data of dateField #83

Closed shawnyang2019 closed 4 months ago

shawnyang2019 commented 4 months ago

some fileds satisfied the fellowing condition: isinstance(self.drf_field, DateField) is True but actual the type of the fields is datetime.date, so it return null accding the coding . i think it is a problem, it set null for existing value.

image

so i add a return as below and solve the problem. pls check it

        try:
            if (
                isinstance(self.drf_field, DateTimeField)
                and type(value) != datetime.datetime
            ):
                return self._parse_date(
                    value, "DATETIME_FORMAT", parse_datetime
                ).replace(tzinfo=None)
            elif isinstance(self.drf_field, DateField) and type(value) != datetime.date:
                return self._parse_date(value, "DATE_FORMAT", parse_date)
            elif isinstance(self.drf_field, TimeField) and type(value) != datetime.time:
                return self._parse_date(value, "TIME_FORMAT", parse_time).replace(
                    tzinfo=None
                )
            return value  #  add this code!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
rptmat57 commented 4 months ago

You think you are correct, I'll make the change