Ticket #3172: datetime_validation_fix_and_tests.patch

File datetime_validation_fix_and_tests.patch, 1.4 KB (added by floguy@…, 8 years ago)

Updated patch to revision 4427 and added unit tests.

  • django_src/django/db/models/fields/__init__.py

     
    437437        Field.__init__(self, verbose_name, name, **kwargs)
    438438
    439439    def to_python(self, value):
     440        if value is None:
     441            return value
    440442        if isinstance(value, datetime.datetime):
    441443            return value.date()
    442444        if isinstance(value, datetime.date):
     
    499501
    500502class DateTimeField(DateField):
    501503    def to_python(self, value):
     504        if value is None:
     505            return value
    502506        if isinstance(value, datetime.datetime):
    503507            return value
    504508        if isinstance(value, datetime.date):
  • django_src/tests/modeltests/validation/models.py

     
    146146>>> p.validate()
    147147{'email': ['Enter a valid e-mail address.']}
    148148
     149# Make sure that Date and DateTime return validation errors and don't raise Python errors.
     150>>> Person(name='John Doe', is_child=True, email='abc@def.com').validate()
     151{'favorite_moment': ['This field is required.'], 'birthdate': ['This field is required.']}
     152
    149153"""}
Back to Top