On Monday 10 July 2006 09:03, Maximillian Dornseif wrote:
> Probably I'm missing something here:
>
> I want 'validation' functionality in admin. E.g. I have the fields
> size, weight and checked_logistics. checked logistics should be only
> allowed to be set True if size and weight are not NULL.
>
> For 'normal' forms Manipulators/Validators seem the way to go. But how
> to get this functionality in Admin?

The same way. Add a validator_list to your field definition. You can write 
your own validator, or use those defined in django core. See 
<http://www.djangoproject.com/documentation/forms/#validators> for a list.

For your case, something like the following would probably do it:

from django.core import validators

def custom_validator(field_data, all_data):
  if field_data == True:
    if all_data['size'] == None and all_data['weight'] == None:
      raise validators.ValidationError("You should provide weight and size      
 
                                        values to set checked_logistics.")

foo = models.CharField(maxlength = 63, unique = True,
                       validator_list = [ custom_validator ]

HTH,
-- 
Kilian CAVALOTTI                      Administrateur réseaux et systèmes
UPMC / CNRS - LIP6 (C870)
8, rue du Capitaine Scott                          Tel. : 01 44 27 88 54
75015 Paris - France                               Fax. : 01 44 27 70 00

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

Reply via email to