Re: custom model field validation

2008-02-08 Thread Jonas Pfeil

> So If I create a newforms field then how do I tell the admin to use
> that when building the form in the admin?

You will need to use the newforms-admin branch to get the admin to use
a newforms field ;)

Btw: If you just want the regex functionality you can use the
RegexField of newforms like so:

def formfield(self, **kwargs):
defaults = {'regex':r"^[A-Za-z][1-9][1-7][0-9]$"}
defaults.update(kwargs)
return super(models.CharField,
self).formfield(form_class=forms.RegexField, **defaults)

Cheers,

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



Re: newforms validator_list

2008-02-04 Thread Jonas Pfeil

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

Not sure about trunk but in newforms-admin at least you can just
subclass your model field and overwrite formfield() to get the admin
to use another form field. That way you can declare a custom form
field (or just a standard one like RegexField) to tweak your
validation for the forms generated from your model by ModelForm or
form_from_instance()/form_from_model().

Cheers,

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