Allow TimeField to specify defaults directly on class

This commit is contained in:
Damien Nozay 2015-01-04 12:30:29 -08:00
parent ff28a6652d
commit 29f494f447

View File

@ -948,12 +948,13 @@ class TimeField(Field):
default_error_messages = { default_error_messages = {
'invalid': _('Time has wrong format. Use one of these formats instead: {format}'), 'invalid': _('Time has wrong format. Use one of these formats instead: {format}'),
} }
# allows subclasses to change defaults
format = api_settings.TIME_FORMAT format = api_settings.TIME_FORMAT
input_formats = api_settings.TIME_INPUT_FORMATS input_formats = api_settings.TIME_INPUT_FORMATS
def __init__(self, format=empty, input_formats=None, *args, **kwargs): def __init__(self, *args, **kwargs):
self.format = format if format is not empty else self.format self.format = kwargs.pop('format', self.format)
self.input_formats = input_formats if input_formats is not None else self.input_formats self.input_formats = kwargs.pop('input_formats', self.input_formats)
super(TimeField, self).__init__(*args, **kwargs) super(TimeField, self).__init__(*args, **kwargs)
def to_internal_value(self, value): def to_internal_value(self, value):