Reputation: 31568
I am saving the form in the view like this
form.save()
but before that i want to set the datetime field to now.
something like
form.timestamp = datetime.now
how can i do that
Upvotes: 1
Views: 75
Reputation: 8982
Better way:
Change the field in your models.py using auto_now_add
and auto_now
:
date = models.DateTimeField(auto_now_add=True, auto_now=True)
In this way, every time you save your form, your field gets updated.
Documentation here.
Upvotes: 3
Reputation: 6272
instance = form.save(commit=False)
instance.timestamp = datetime.now
instance.save()
JD
Upvotes: 0