> I understand the preferred method is to create a custom form Field,
> and do validation in its clean() method.  However, this appears to be
> lacking in a couple ways.

This can be accomplished at the form level by defining a clean_FIELD 
method to clean the data as you see fit. The only time you would need 
to write your own custom field is to completely override a the default 
validation of a field.

> 
> First of all, it assumes you're generating the form manually.  What if
> you're using form_for_model, or more critically, using the admin
> interface?  Is there a way to specify custom form Field instances for
> a corresponding model Field in the admin?

Ok, this seems to be a large misconception of what newforms-admin 
really is. Let's pretend the admin application doesn't exist for one 
second. You are left with newforms. You could go on your merry way 
writing forms that only authenticated users can access. Putting the 
admin application back in the mix isn't trying to stop you from doing 
that. It just provides you a thin layer of views, urls and many 
sensible defaults for an admin interface using newforms.

The ModelAdmin class has two methods named form_add and form_change. 
This function returns a django.newforms.Form instance that will be used 
to render on the page. You could return anything from here. 
form_for_model should not be used and its ModelForm replacement is 
preferred. I am not 100% sure off the top of my head if there are any 
particular requirements the form must have, but if you notice anything 
wonky, please, open a ticket in Trac.

> 
> Secondly, in the admin the potential to do multi-field validation is
> gone (or seems to be).  The old validator function passed the values
> (field_data, all_data), allowing one to check the value of other
> fields in the form via the all_data field.  Is it no longer possible
> to, for instance, trigger validation of one field off another via the
> admin in newforms-admin?  (ie, if field1 is None, field2 is required;
> if field1 is filled, field2 is not required.)

As I pointed out above this is still newforms. This type of validation 
is very possible since the form clean_FIELD methods are never passed 
its own value. It is the job of the developer to pull out the values 
from cleaned_data that a clean_FIELD method, you are implementing, 
should care about.

-- 
Brian Rosner
http://oebfare.com



--~--~---------~--~----~------------~-------~--~----~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to