1👍
Update:
I figured that default=datetime.date.now
behaved like auto_now_add=True
because you mentioned that your template only contains the text
field.
It turns out your situation is not handled any differently and you must display the date
field in your form.
If you want to ignore it, you can override the ModelForm.save
method to set the date yourself, or add it in your model save()
definition.
You should look into the auto_now_add=True
parameter in model field definitions which automatically adds this behavior of setting a date field to datetime.datetime.now()
upon the first save.
date = models.DateTimeField(auto_now_add=True)
0👍
You should write
default = datetime.datetime.now()
with parentheses to call function ang get datetime. There is auto_now field to do this in better way. https://docs.djangoproject.com/en/dev/ref/models/fields/#datefield
These is another way to provide initial data from view:
form = CommentForm( initial = { 'date': datetime.datetime.now(), 'text': u'', }
Read more on https://docs.djangoproject.com/en/dev/ref/forms/fields/#initial
- [Answer]-Django-1.4.3 how to add categories?how posts when click on the category?
- [Answer]-What is the most efficient structure to save data in my database?
- [Answer]-Django remove least recent many to many entry
- [Answer]-Ajax post to Django view CSRF forbidden
- [Answer]-Bring data from a process_response middleware to a template