Adrian Holovaty wrote:
>
> EXAMPLE CODE:
>
> class Person(models.Model):
> name = models.CharField(maxlength=50)
> birthday = models.DateField()
> favorite_number = models.IntegerField()
>
>>>> p = Person(name='Joe', birthday='never', favorite_number='foo')
>>>> p.validate()
> {'birthday': 'Enter a valid date in YYYY-MM-DD format.',
> 'favorite_number': 'This value must be an integer.'}
>>>> p = Person(name='Joe', birthday='2005-1-3', favorite_number='34')
>>>> p.validate()
> {}
>>>> p.birthday
> datetime.date(2005, 1, 3)
>>>> p.favorite_number # note this is an integer now, no longer a string
> 34
>
>
> Thoughts, criticisms? The only part I'm sketchy on is the side effect
> of converting the values to their Python data types. The
> cleanliness/consistency is quite nice, but it's slightly not something
> a developer might expect. However, we can solve the latter through
> clear documentation.
>>> p1 = Person(name='Joe', birthday='2005-1-3', favorite_number='foo')
>>> p2 = Person(name='Jack', birthday = datetime.date(2005,1,3),
favorite_number='foo')
>>> p1.birthday == p2.birthday
False
i don't know. i understand that this would make life easier, but on the
other hand, it does not feel good for me :) some points:
- explicit is better than implicit
- we're removing the magic there or adding it back? :-)
- does this not tie too much the web-layer to the db-layer?
basically.. what does the developer win with the auto-conversion?
perharps some use-case scenarios would help to explain it to us...
summary:
it's a very cool change. i'm just not sure about the auto-conversion part.
gabor
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-developers
-~----------~----~----~----~------~----~------~--~---