On 3/10/07, Malcolm Tredinnick <[EMAIL PROTECTED]> wrote:
> Validation happens on the strings submitted from a form, *before* they
> are converted to Python objects (since there's no guarantee we can
> convert them without error). We do not have model-aware validation at
> the moment, but it is coming. Note that what we do have is still good
> for the majority of cases, because you have access to all the submitted
> fields. What you don't have access to is the instance of the model that
> will be affected in the case where you are updating an existing
> instance. That is the feature we will add eventually.

Having to validate the data at every possible form location doesn't
seem very DRY to me.  I should be able to put a single set of
validation rules directly in the model so any form I write in the
future has to validate against them.

> See http://www.djangoproject.com/documentation/forms/#validators for a
> description of how validators work. Although that page talks about
> validators in the context of form submissions, they are the same
> validators that you can specify on models.*Field classes as well.

The newforms page doesn't have much about validation on it:

http://www.djangoproject.com/documentation/newforms/

Do the same validation techniques apply from the old forms system to
the newforms?

> Suffice it to say that, in your case, when you submit a string as part
> of a form submission to go into your field, Django will ensure that it
> is non-empty, because you have blank=False.

That doesn't seem to be the case for this particular field I have:

class List(models.Model):
    name = models.CharField(maxlength=32, blank=False, null=False)

> python manage.py shell
In [1]: import datetime
In [2]: from mysite.groceries.models import List
In [3]: l = List(name='', created_at=datetime.datetime.now())
In [4]: l.save()
In [5]: l.name
Out[5]: ''

What am I missing here?


-- 
Greg Donald
http://destiney.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