kmh wrote:
>> This breaks semantics of a property of an object: you should be able to
>> read exactly what you just set. Imagine explaining this magic to a newbie:
>>
>>     c.crime_date = request.POST['crime_date'] ## user submits '2006-1-2'
>>     if c.crime_date == '2006-1-2': ## false!
>>         ...
>>
>> Of course you can define comparision with strings etc... But this leads
>> to even more magic.
> 
> Isn't this the magic that we explicitly request when we specify a
> model?  Is this less confusing:
> 
> c.crime_date = request.POST['crime_date'] ## user submits '2006-1-2'
> c.crime_date == '2006-1-2' # true
> c.save()
> c.crime_date == '2006-1-2' # false!
> 
> If an attribute is going to be magic it should be consistently magic.
> Practicality beats purity here, I think.  In practice you need to be
> familiar enough with your models to understand what is happening here
> for them to be any use at all.

what about this approach? :

===================================================
def post2datetime(post_date):
        p = time.strptime(post_date,'%Y-%m-%d')
        return datetime.datetime(p[0],p[1],p[2])


c.crime_date = post2datetime(request.POST['crime_date'])
c.save()
c.crime_date == datetime(2006,1,2) # true
===================================================

and you only have to write the post2datetime function only once.
it can even be a convenience function offered by django.
but i think that such conversion should not be automatic, because it 
feels unpythonic. at least for me. i would maybe expect perl to 
auto-convert such strings, but not python.

Explicit is better than implicit..... :)

gabor

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django developers" group.
To post to this group, send email to django-developers@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-developers
-~----------~----~----~----~------~----~------~--~---

Reply via email to