Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Datetimefield is serialized to str #27

Closed
martinwk opened this issue Aug 24, 2017 · 1 comment
Closed

Datetimefield is serialized to str #27

martinwk opened this issue Aug 24, 2017 · 1 comment

Comments

@martinwk
Copy link

When I serialize this model

    site            = models.ForeignKey(Site, on_delete=models.CASCADE)
    name         = models.CharField(max_length=100, )
    start_date_time = models.DateTimeField(auto_now=False, auto_now_add=False, verbose_name='Date and time at which the well is deployed.')

with this serializer

class FileSerializer(serializers.ModelSerializer):
    class Meta:
        model = Well
        fields = ('id', 'name', 'site', )

The resulting dataframe has a column start_date_time but this is a string rather than a datetime object. I work around this by using transform_dataframe and convert the column using pandas.to_datetime function. Is this the way to go or am I missing someting?

@sheppard
Copy link
Member

sheppard commented Sep 1, 2017

You can turn off the string serialization by adding the following to your serializer:

class FileSerializer(serializers.ModelSerializer):
    start_date_time = serializers.DateTimeField(format=None)

I updated the README with more information.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants