shymonk/django-datatable

DatetimeColumn

mmingle opened this issue · 2 comments

When I try to initialize a DatetimeColumn I get the error

/lib/python2.7/site-packages/django_datatable-0.1.2-py2.7.egg/table/columns/datetimecolumn.py", line 17, in render return datetime.strftime(self.format)
AttributeError: 'SafeText' object has no attribute 'strftime'

I got around this sort of, I overrode get_quertset() and converted it there, but everytime the table is sorted it switches back to the default format.

the same issue happens to me. would you explain a bit more your workaround @mmingle please?.
thanks!

Ya @pguridi like i said it's still not quite working, when you sort the column it goes back to normal..

In my views.py

class YourTableData(FeedDataView):
    token = YourTable.token

    def get_queryset(self):
        current_user = self.request.user
        yourqueryset = YourModel.objects.all()
        for object in yourqueryset:
            object.datetime = object.datetime.strftime('%b %d,%Y, %r')
        return yourqueryset

Then in your tables.py, or wherever you keep the table models

class YourTable(Table):
    id = Column(field='id', header=u'ID')
    name = Column(field='name', header=u'Name')
    class Meta:
        model = YourModel
        ajax = True
        ajax_source = reverse_lazy('YourTableData')
        attrs = {'class': 'table table-striped table-boardered table-hover dataTable'}

When i figure the sorting part out i will post it up here