I have a timestamp field in one of my Django models (let's say Comment). I have been using Django-tastypie
for REST API. Now when a POST
request is submitted to /api/v1/comments/
, a new comment object is created but how do I populated the timestamp
field in this comment. I want this timestamp to be that when the server receives the POST request.
So, how do I intercept this POST request and put this timestamp field?
Django has the auto_now
and auto_now_add
feature that you can use to automatically fill in the time on a DateTime Field. Such as:
created_at = models.DateTimeField(auto_now_add=True)
https://docs.djangoproject.com/en/1.8/ref/models/fields/#datefield