Ticket #7860: fix_supports_usecs.diff
File fix_supports_usecs.diff, 2.4 KB (added by , 16 years ago) |
---|
-
django/db/models/fields/__init__.py
523 523 def get_manipulator_field_objs(self): 524 524 return [oldforms.CommaSeparatedIntegerField] 525 525 526 def fix_supports_usecs(value): 527 if value is not None: 528 # SQLServer will throw a warning if microseconds are given, because it 529 # doesn't support microseconds. 530 if not connection.features.supports_usecs and hasattr(value, 'microsecond'): 531 value = value.replace(microsecond=0) 532 return value 533 526 534 class DateField(Field): 527 535 empty_strings_allowed = False 528 536 def __init__(self, verbose_name=None, name=None, auto_now=False, auto_now_add=False, **kwargs): … … 551 559 552 560 def get_db_prep_lookup(self, lookup_type, value): 553 561 if lookup_type in ('range', 'in'): 554 value = [smart_unicode( v) for v in value]562 value = [smart_unicode(fix_supports_usecs(v)) for v in value] 555 563 elif lookup_type in ('exact', 'gt', 'gte', 'lt', 'lte') and hasattr(value, 'strftime'): 556 564 value = datetime_safe.new_date(value).strftime('%Y-%m-%d') 557 565 else: 558 value = smart_unicode( value)566 value = smart_unicode(fix_supports_usecs(value)) 559 567 return Field.get_db_prep_lookup(self, lookup_type, value) 560 568 561 569 def pre_save(self, model_instance, add): … … 642 650 643 651 def get_db_prep_lookup(self, lookup_type, value): 644 652 if lookup_type in ('range', 'in'): 645 value = [smart_unicode( v) for v in value]653 value = [smart_unicode(fix_supports_usecs(v)) for v in value] 646 654 else: 647 value = smart_unicode( value)655 value = smart_unicode(fix_supports_usecs(value)) 648 656 return Field.get_db_prep_lookup(self, lookup_type, value) 649 657 650 658 def get_manipulator_field_objs(self): … … 1107 1115 else: 1108 1116 prep = smart_unicode 1109 1117 if lookup_type in ('range', 'in'): 1110 value = [prep( v) for v in value]1118 value = [prep(fix_supports_usecs(v)) for v in value] 1111 1119 else: 1112 value = prep( value)1120 value = prep(fix_supports_usecs(value)) 1113 1121 return Field.get_db_prep_lookup(self, lookup_type, value) 1114 1122 1115 1123 def pre_save(self, model_instance, add):