kmh wrote: >Or we could have an update() method that took multiple arguments like >the constructor. If two fields do depend on each other for validity >then it makes sense that you can't set them separately. > > This makes sense. However setting several fields at once is only one of the problems. I can't invent another useful example right now but think of cases when you need to set some property, pass the object to some calculating function and use its result to set another property. I.e. when something forces you to set fields separately in time but they are both required.
>Isn't this the magic that we explicitly request when we specify a >model? > Uhm... I, myself, never expected this :-). When I say "crime_date = meta.DateField()" I merely expect it to work as close as possible to Python date. > 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! > > It is confusing. That's why I propose something like this: c.crime_date = meta.DateField.from_str(request.POST['crime_date']) or c.crime_date = datetime.date(*strptime(request.POST['crime_date'])[0:3]) Second variant is ugly but I don't know a better way to convert str to datetime in Python. Anyway I mean that user should convert strings explicitely either to Dajngo's field types or to Python's native types. I think it shouldn't be magical here because user shouldn't use this often at all. I think automatisation of converting a form to an object should happen a level higher like this: c = Crime.parse_form_data(request.POST) parse_form_data would iterate over field objects and try to set them using their own convertion methods: field=field.from_str(request.POST.get(field.name,'')) I beleive that cases when you need to set fields explicitely are rarely related to handling form input where all values are strings. >If an attribute is going to be magic it should be consistently magic. > > I completely agree with consistency. But I still think that attributes should be magical. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---