How to add a default time (but not date) to a DateTimeField in DJango?
I have a DateTimeField on a model. In the forms for that model, I use the SplitDateTimeWidget. I want to enable users to enter just a date, and have开发者_开发问答 my code define a default time (like 2 p.m.) if one is not entered.
Is there a simple way to do this? Since this is needed for multiple forms, I would like to have a way that can be applied to all of the forms at once, instead of having to be re-implemented for each one.
You may be able to do this by subclassing DateTimeField and over-riding the clean() method.
I tend to do these types of defaults in the models save() method or when the pre_save signal is called.
精彩评论