4👍
Two approaches:
First you could modify the view to create a field and add it to the form when you save the response. Something like:
if form.is_valid() :
timestamp = datetime.now()
... save it, print it, whatever...
The better way is to handle it at model level, and just have a field for it.
created_at = models.DateTimeField(auto_now_add=True)
Now when you save the input to your DB, you’ve got creation time of when the save() method was called.
8👍
If you mean when you’re processing the form in the view, then why not just use datetime.datetime.now() at any point in the view? That’ll be milliseconds after the user pressed Submit
- [Django]-How to combine select_related() and value()?
- [Django]-What do I add to my requirements.txt in Django directory in order to push it to Heroku?
- [Django]-Django post_save and south migrations
0👍
Http get/post operations don’t send the time to the server so as stevejalim mentions you can get the a timestamp in your server side code. Alternatively, you can pass an additional parameter representing the time the user clicked/submitted the page. You would set the parameter using javascript:
$('#form1').submit(function() {
var input = $("<input>").attr("type", "hidden").attr("name", "timestamp").val(new Date().getTime());
$('#form1').append($(input));
return true;
}
- [Django]-Caught DoesNotExist while rendering: Photo matching query does not exist
- [Django]-How to cast Django form to dict where keys are field id in template and values are initial values?
- [Django]-Populate() isn't reentrant Django Google App Engine
- [Django]-Upload image files with specific directory structure to amazon s3 django