This is my article model:
class Article(models.Model):
url = models.CharField(max_length=256)
headline = models.CharField(max_length=256)
source = models.ForeignKey(Source)
datetime_ingested = models.DateTimeField(auto_now_add=True)
content = models.TextField()
image_src = models.CharField(max_length=256, null=True)
And this is my serializer:
class ArticleSerializer(serializers.ModelSerializer):
class Meta:
model = Article
fields = ('id', 'url', 'headline', 'source', 'datetime_ingested', 'content', 'image_src')
All date time fields are in UTC, and I want to convert the time to the client's localtime. Is this possible to do from the framework's side? Right now I'm serving the content, parsing the date using moment.js
(https://momentjs.com/) to display contextual datetime based on the current timezone like so:
moment(article['datetime_ingested'], "YYYY-MM-DD hh:mm:ss").fromNow()
But this translates UTC to now. Is it possible to tell Django to serve the datetime fields in the client's timezone?
The datetime string looks like so:
2017-01-26T03:49:34.232000Z