On 5/4/06, Kilian CAVALOTTI <[EMAIL PROTECTED]> wrote: > class Obj(models.Model): > name = models.CharField(maxlength=80, blank=False)
Per the model documentation, 'blank=False' does only apply when entering a value in the admin[1]. But that's not a very satisfying answer, so here's a fuller explanation of what's going on in your examples: The key difference here is between 'blank=False', which applies only to the admin app, and 'null=False', which applies to the database. By default, a field's 'null' attribute is False, which means the DB column generated from the model will not accept a value of NULL. You'd think this would result in an error when you try to save any field with a null value, but this is actually dependent on the *type* of field, which is why there's an apparent inconsistency. A CharField translates to a Python string, which means that when you don't enter a value it translates to an empty string. Which, because it's not the value NULL, is accepted by the DB. An IntegerField, however, translates to a Python int, which does not have an "empty" variation as strings do, so I'd imagine that not filling it in results in conversion to... NULL. Which the DB rejects. So long as you're only using the admin app to create objects, this will be fine, but if objects are going to be created from other views you'll want to set up a custom manipulator which raises an exception when the CharField is left blank or, if you're going to be creating objects programmatically as in your examples with the Python interpreter, you'll want to override the model's save() method to make it raise an exception when the incoming value for the CharField is an empty string [1]http://www.djangoproject.com/documentation/model_api/#blank -- "May the forces of evil become confused on the way to your house." -- George Carlin --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---