Malcolm, As a relatively new Django user but experienced web developer I just found it counter-intuitive that the Form would set fields that are nowhere specified or even mentioned in the request. To follow your line of thought, a validation error should be raised if a required field is not present, but this is not the case, the missing value is just replaced silently by a default value. The empty string for me is just an arbitrary value as would be any other value - it is highly application dependent if the empty string is a sensible default value for missing values.
On Jan 9, 2:18 am, Malcolm Tredinnick <malc...@pointy-stick.com> wrote: > On Thu, 2009-01-08 at 07:08 -0800, Flo Ledermann wrote: > No. Don't ask the form class to read your mind. Create a form that knows > which fields it expects so that errors can be raised correctly and > validation will occur normally. I am not asking the form class to read my mind but to read the request. I just didn't realize that django's Form concept is very presentation oriented and is really (besides other things) a helper for rendering forms in the template. I do not want to create a ModelForm class for all possible subsets of fields I am going to use in the presentation layer for updating the model (besides that, in a clearly seperated scenario, I couldn't know in advance which fields will be used in the presentation). What I want from a server-side form class is a way of specifying how an incoming *request* is mapped to a create/update operation on the model, no matter from which form of presentation this request emerged. To conclude, I believe there are three ways of dealing with missing fields in the request: 1. Raise a validation error 2. Set the field to a default value or NULL 3. Ignore the field if not required or an update operation an an existing instance is performed In my opinion, items 1) and 3) are most intuitive and equally consistent, so they should be chooseable by a flag. Option 2) is a bit arbitrary in my opinion, but this is what django does. Please correct me if I am wrong or if I am missing something, but even after skipping through the source code of the form classes this is the view that i got. Best regards, Flo --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---