joshourisman / django-tablib

django-tablib is a helper library for Django that allows Django models to be used to generate tablib datasets with introspection of the fields on the models if no headers are provided. If headers are provided they can reference any attribute, fields, properties, or methods on the model.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

date format on export with TablibAdmin

tingletech opened this issue · comments

Hi, I'm using TablibAdmin to export from the django admin (on google app engine with django-nonrel if that matters) and a user is complaining that they need the dates in "ISO" CCYY-MM-DD format rather than US "MM/DD/CCYY". I'm not sure if this is a tablib issue or a django issue or a django-tablib issue. Can you give me any hints on how to make this change?

At the moment, the date format actually is configurable. It's using Django's SHORT_DATE_FORMAT setting (as well as django.template.defaultfilters.date) to format datetime objects. So currently the way to configure the date format is to set SHORT_DATE_FORMAT to your desired format in your settings.py. You can see how this works here: https://github.com/joshourisman/django-tablib/blob/master/django_tablib/base.py#L27

Moving forward I want to add Django model/form-field style DatasetFields so that you can easily customize any or all of the fields in your Dataset. So eventually the idea is that you'll be able to do something like this when defining your Dataset:
class MyModelDataset(ModelDataset):
boring_date_field_name = fields.DateField(label="ISO Formatted Date", format="c")

    class Meta:
        model = MyModel

Tablib v0.9.5 was just released, which adds the dataset.add_formatter(column, callback) method.