News for hackers. Stuff that matters.
Re:Overloading Django Form Fields by cma on Wednesday March 27, 2013 @01:25PM (#5450715)
less magic:

     from django.db import models
    +from django.core.exceptions import ValidationError
     
    +def not_empty(value):
    +    if value == u'': raise ValidationError(u'Empty value')
     
     class MyModel(models.Model):
    -    name = models.CharField(max_length=50, blank=True)
    +    name = models.CharField(max_length=50, blank=True, validators=[not_empty])
Re:Overloading Django Form Fields by whubr on Wednesday March 27, 2013 @03:19PM (#5451431)
Blank is purely for validation and has nothing to do with the database constraints. If you want to prevent empty input just remove 'blank=True', surely?

https://docs.djangoproject.com/en/dev/ref/models/fields/#bla...

Re:Overloading Django Form Fields by cma on Wednesday March 27, 2013 @03:25PM (#5451463)
Yep, I assumed that wasn't the case based on the blog post's goal of avoiding changing the schema (I thought blank=True must be adding a CHECK (column_name <> '') constraint or something).
Re:Overloading Django Form Fields by obviouslygreen on Wednesday March 27, 2013 @01:52PM (#5450917)
Re:Overloading Django Form Fields by eurleif on Wednesday March 27, 2013 @11:21PM (#5453204)
'if not value.strip():' is a more thorough check that I think is better in most cases.
Re:Overloading Django Form Fields by pydanny on Wednesday March 27, 2013 @01:27PM (#5450727)
Nice!