Hi,
check out ticket #6845 ( http://code.djangoproject.com/ticket/6845 ).
It enables you to define validators on both DB Fields and FormFields
and should make your work much easier.

On Sun, Apr 13, 2008 at 6:09 PM, Steven Armstrong <[EMAIL PROTECTED]> wrote:
>
>  Hi
>
>  I've made a small change to the ModelForm framework to allow declarative
>  definition of validators. This allows for quick and easy reuse of
>  validators and means I have to write less clean_foo methods. This works
>  both in the admin as in custom views.
>
>
>  What used to be written like this:
>
>  class Domain(models.Model):
>      name = models.CharField(_('Name'), max_length=255, unique=True,
>          validator_list=[validators.isValidHostName])
>      active = models.BooleanField(_('Active'), default=True)
>
>
>  Could then be written like this:
>
>  class Domain(models.Model):
>      name = models.CharField(_('Name'), max_length=255, unique=True)
>      active = models.BooleanField(_('Active'), default=True)
>
>  class DomainModelForm(forms.ModelForm):
>      class Meta:
>          model = Domain
>          validators = {
>              'name': [validators.isValidHostName],
>          }
>
>
>  And can be used in the admin like this:
>
>  from foo.forms import DomainModelForm
>  from foo.models import Domain
>  class DomainAdmin(admin.ModelAdmin):
>      list_display = ('name', 'active')
>      list_filter = ('active',)
>      search_fields = ('name',)
>      form = DomainModelForm
>  admin.site.register(Domain, DomainAdmin)
>
>
>  Anybody interested in this?
>  Is it worth opening a ticket with a patch?
>
>  Cheers
>  Steven
>
>  >
>



-- 
Honza Král
E-Mail: [EMAIL PROTECTED]
ICQ#: 107471613
Phone: +420 606 678585

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to