Hi all, I thought model properties validation would occur at object creation/modification, but it seems that it's not the case.
(To be complete, I'd like to precise that I use the current svn trunk, and that I ran a 'manage.py reset project' between each model modification) * First, I tried to define a model as following: class Obj(models.Model): name = models.CharField(maxlength=80, blank=False) Correct me if I'm wrong, but we could expect to get an IntegrityError saying that the object's name can't be empty if I try to create an object with no defined name. But well, no error is reported: >>> from project.models import Obj >>> o = Obj() >>> o.save() >>> o.name '' >>> However, if I try to add a new Obj with the admin interface, I get a 'This field is required.' error message, as expected. * Then I created an other class with an Integer property, which generates the right IntegrityError when saving the object with an empty field: class Obj2(models.Model): name = models.IntegerField() >>> from project.models import Obj2 >>> o = Obj2() >>> o.save() Traceback (most recent call last): File "<console>", line 1, in ? File "/home/kilian/django/django/db/models/base.py", line 185, in save ','.join(placeholders)), db_values) File "/home/kilian/django/django/db/backends/util.py", line 12, in execute return self.cursor.execute(sql, params) File "/home/kilian/django/django/db/backends/sqlite3/base.py", line 69, in execute return Database.Cursor.execute(self, query, params) IntegrityError: localView_obj2.name may not be NULL >>> Right, that's expected behaviour. * Now, let's see what's happening if I add a blank=True option to my Obj2 model definition: class Obj3(models.Model): name = models.IntegerField(blank=True) >>> from project.models import Obj3 >>> o = Obj3() >>> o.save() Traceback (most recent call last): File "<console>", line 1, in ? File "/home/kilian/django/django/db/models/base.py", line 185, in save ','.join(placeholders)), db_values) File "/home/kilian/django/django/db/backends/util.py", line 12, in execute return self.cursor.execute(sql, params) File "/home/kilian/django/django/db/backends/sqlite3/base.py", line 69, in execute return Database.Cursor.execute(self, query, params) IntegrityError: localView_obj3.name may not be NULL >>> Duh, I can't have a blank Integer field... It's the same with a PositiveInteger(), which allow to save negative values (not from the admin interface, only when manipulating python objects). All this seems to show that fields type and contents validation does not occur at object creation, but only in the admin interface. Is this a wanted behavior, or an issue? TIA, Best regards, -- Kilian CAVALOTTI Administrateur réseaux et systèmes UPMC / CNRS - LIP6 (C870) 8, rue du Capitaine Scott Tel. : 01 44 27 88 54 75015 Paris - France Fax. : 01 44 27 70 00 --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---