mirror of
https://github.com/django/django.git
synced 2025-08-03 10:34:04 +00:00
Fixed #7560 -- Moved a lot of the value conversion preparation for
loading/saving interactions with the databases into django.db.backend. This helps external db backend writers and removes a bunch of database-specific if-tests in django.db.models.fields. Great work from Leo Soto. git-svn-id: http://code.djangoproject.com/svn/django/trunk@8131 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
7bc728c826
commit
b3b71a0922
11 changed files with 318 additions and 135 deletions
|
@ -16,6 +16,7 @@ class Person(models.Model):
|
|||
birthdate = models.DateField()
|
||||
favorite_moment = models.DateTimeField()
|
||||
email = models.EmailField()
|
||||
best_time = models.TimeField()
|
||||
|
||||
def __unicode__(self):
|
||||
return self.name
|
||||
|
@ -28,7 +29,8 @@ __test__ = {'API_TESTS':"""
|
|||
... 'name': 'John',
|
||||
... 'birthdate': datetime.date(2000, 5, 3),
|
||||
... 'favorite_moment': datetime.datetime(2002, 4, 3, 13, 23),
|
||||
... 'email': 'john@example.com'
|
||||
... 'email': 'john@example.com',
|
||||
... 'best_time': datetime.time(16, 20),
|
||||
... }
|
||||
>>> p = Person(**valid_params)
|
||||
>>> p.validate()
|
||||
|
@ -130,6 +132,22 @@ datetime.datetime(2002, 4, 3, 13, 23)
|
|||
>>> p.favorite_moment
|
||||
datetime.datetime(2002, 4, 3, 0, 0)
|
||||
|
||||
>>> p = Person(**dict(valid_params, best_time='16:20:00'))
|
||||
>>> p.validate()
|
||||
{}
|
||||
>>> p.best_time
|
||||
datetime.time(16, 20)
|
||||
|
||||
>>> p = Person(**dict(valid_params, best_time='16:20'))
|
||||
>>> p.validate()
|
||||
{}
|
||||
>>> p.best_time
|
||||
datetime.time(16, 20)
|
||||
|
||||
>>> p = Person(**dict(valid_params, best_time='bar'))
|
||||
>>> p.validate()['best_time']
|
||||
[u'Enter a valid time in HH:MM[:ss[.uuuuuu]] format.']
|
||||
|
||||
>>> p = Person(**dict(valid_params, email='john@example.com'))
|
||||
>>> p.validate()
|
||||
{}
|
||||
|
@ -153,5 +171,7 @@ u'john@example.com'
|
|||
[u'This field is required.']
|
||||
>>> errors['birthdate']
|
||||
[u'This field is required.']
|
||||
>>> errors['best_time']
|
||||
[u'This field is required.']
|
||||
|
||||
"""}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue