On 2/22/06, Adrian Holovaty <[EMAIL PROTECTED]> wrote:
>
> Let's return to this subject, which was discussed a couple of weeks
> ago. Here's my latest thinking on the subject.
>
> * Automatic manipulators go away. Instead of messing with those, to
> create a new model object you try instantiating it. Validation errors
> are raised at that point. Example:
>

I think obj.save() and obj.save(validate=False) would be the best way
to do this given the issues raised by others in this thread.


> * As a side effect, multiple input types would need to be allowed for
> certain field types. For example, a date field should accept either a
> datetime object or a string in the correct format. Fields should
> normalize input data to the correct internal type (in this case, a
> datetime object) when the __setattr__() happens. For example, both of
> these model attribute assignments would be valid:
>
>     c.crime_date = datetime.date(2006, 1, 2)
>
>     c.crime_date = '2006-1-2'
>
> In the second example, c.crime_date would immediately be converted to
> a datetime.date object. What are the pitfalls to this approach?

I would much rather see something similar to, but simpler than
automatic manipulators here. I think the job of translating post data
into python types should be handled *outside* of the model, although
the logic to do so could very well be in methods of a field. Something
like html2python and python2html. Maybe some sort of prep_data
function could take care of this as well. We discussed this the first
time you brought it up. We still need a way to grab the fields that
apply to a model from the post data, or view will have to set every
attribute one by one.

prep_data would take the request, and return a dict suitable to pass
to the objects constructor. FWIW I think prep_data is a bad name
though. Other suggestions?

Maybe something like this:

new_data = MyModel.prep_data(request)
my_obj = MyModel(new_data)

or

new_data = prep_data(MyModel, request)
my_obj = MyModel(new_data)

Joseph

--~--~---------~--~----~------------~-------~--~----~
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