How can I set the default value as today date in a model?
My model: vote_date = models.DateField(_('vote date'), null=False, blank=False)
How can I set the default value as today date in a model?
My model: vote_date = models.DateField(_('vote date'), null=False, blank=False)
Use
auto_now_add
instead, asauto_now
would change the vote date any time the object is modified.http://docs.djangoproject.com/en/dev/ref/models/fields/#django.db.models.DateField.auto_now_add
django command extensions
can help you with many things like:http://code.google.com/p/django-command-extensions/
None of the answers solve the original problem. Restating the problem, how can I set the default value of a date field to todays date and still let the user override the default.
From the DJango docs:
The answer if this is not just a "when was this added/edited" field, is to use
note no parens. This sets the default to the function, not the value returned by the function when the model is evaluated.
This resolve my problem:
More info about django fields...