我们从Python开源项目中,提取了以下38个代码示例,用于说明如何使用django.forms.TimeField()。
def __init__(self, verbose_name=None, name=None, auto_now=False, auto_now_add=False, **kwargs): self.auto_now, self.auto_now_add = auto_now, auto_now_add if auto_now or auto_now_add: kwargs['editable'] = False kwargs['blank'] = True super(TimeField, self).__init__(verbose_name, name, **kwargs)
def deconstruct(self): name, path, args, kwargs = super(TimeField, self).deconstruct() if self.auto_now is not False: kwargs["auto_now"] = self.auto_now if self.auto_now_add is not False: kwargs["auto_now_add"] = self.auto_now_add if self.auto_now or self.auto_now_add: del kwargs['blank'] del kwargs['editable'] return name, path, args, kwargs
def get_internal_type(self): return "TimeField"
def pre_save(self, model_instance, add): if self.auto_now or (self.auto_now_add and add): value = datetime.datetime.now().time() setattr(model_instance, self.attname, value) return value else: return super(TimeField, self).pre_save(model_instance, add)
def get_prep_value(self, value): value = super(TimeField, self).get_prep_value(value) return self.to_python(value)
def __init__(self, input_formats=None, format=None, *args, **kwargs): self.input_formats = input_formats if input_formats is not None else self.input_formats self.format = format if format is not None else self.format super(TimeField, self).__init__(*args, **kwargs)
def test_should_time_convert_string(): assert_conversion(forms.TimeField, graphene.String)
def get_form_field(self, **kwargs): """Return a Django form field appropriate for a time property. This defaults to a TimeField instance, except if auto_now or auto_now_add is set, in which case None is returned, as such 'auto' fields should not be rendered as part of the form. """ if self.auto_now or self.auto_now_add: return None defaults = {'form_class': forms.TimeField} defaults.update(kwargs) return super(TimeProperty, self).get_form_field(**defaults)