Hi Maciej,
Yes, I've looked at the validator-list code before, but I don't
understand how to implement it.
The example code is:
from django.core import validators
from django import forms
class ContactManipulator(forms.Manipulator):
def __init__(self):
self.fields = (
# ... snip fields as above ...
forms.EmailField(field_name="to",
validator_list=[self.isValidToAddress])
)
def isValidToAddress(self, field_data, all_data):
if not field_data.endswith("@example.com"):
raise validators.ValidationError("You can only send
messages to example.com e-mail addresses.")
...but if I wanted to use this with a model I have written, where in
the world does this code go? Is class ContactManipulator a subclass of
my Model? Is the sample code a separate file that I reference? I'm
using the newforms admin, so I'm assuming this code would be a
subclass of my admin.ModelAdmin...? I can hack away at this, but I
want to make sure I'm staying as close to best practices for Django as
I can, and I'm only two months into it.
Thanks for your help and patience,
Brandon
On May 15, 8:05 am, Pigletto <[EMAIL PROTECTED]> wrote:
> On 15 Maj, 03:43, Brandon Taylor <[EMAIL PROTECTED]> wrote:> I saw this
> example in the
> documentation:http://www.djangoproject.com/documentation/forms/#validators
>
> > But where does this code live? Does this go into my models.py as a
> > subclass of my Model, or is it a separate file?
>
> Link you've submitted is referenced
> by:http://www.djangoproject.com/documentation/model-api/#validator-list
>
> You may also take a look at: django/db/models/fields/__init__.py to
> see how validators are processed.
>
> --
> Maciej Wisniowski
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" 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-users?hl=en
-~----------~----~----~----~------~----~------~--~---