On Jan 12, 2008 1:17 PM, Ian J Cottee <[EMAIL PROTECTED]> wrote: > > I've actually written a couple of basic apps in Django but today I > thought I'd play around with doc tests and realised I didn't know as > much as I thought I did. This is all done with latest trunk. > > Let's take a model definition that has just the following: > > class PartType(models.Model): > code = models.CharField(max_length=15) > description = models.CharField(max_length=50) > > We can play around with this in the shell and do this: > > >>> pt = PartType() > >>> pt.validate() > {'code': [u'This field is required.'], 'description': [u'This field is > required.']} > > Which is what we expect. These two fields are required. > > >>> pt.code='ACODE' > >>> pt.description='A description' > >>> pt.validate() > {} > >>> pt.save() > > All good, it validates and saves. Now let's give it something a little > longer than it can't cope with. > > >>> pt.code='THISISLONGERTHANFIFTEENCHARS' > >>> pt.validate() > {} > > Odd - it validates but we know our code field can only be 15 characters. > > >>> pt.save() > Traceback (most recent call last): > File "<console>", line 1, in <module> > File > "/usr/local/lib/python2.5/site-packages/django/db/models/base.py", line > 238, in save > db_values + self._meta.pk.get_db_prep_lookup('exact', pk_val)) > File > "/usr/local/lib/python2.5/site-packages/django/db/backends/util.py", > line 18, in execute > return self.cursor.execute(sql, params) > ProgrammingError: value too long for type character varying(15) > > BANG! > > I'd be expecting for Django to tell me before postgres does, that the > field does not validate. Am I misunderstanding something? >
Did you miss the "This is an experimental feature!" note at the top of: http://www.djangoproject.com/documentation/models/validation/ ? Last I recall seeing it mentioned here, model validation is still a work in progress. Meaning I don't believe everything is supposed to work just yet. Karen --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---