On Apr 17, 5:58 am, Horacio de Oro <hgde...@gmail.com> wrote: > Hi! I've a problem with Django not validating my 'CharField's. Maybe > I'm misunderstanding the docs, and Django doesn't do this kind of > validations? > > I've made a simple example. This is the model: > > class SimpleModelC(models.Model): > name=models.CharField(max_length=256) > image_content_type=models.CharField(max_length=32, null=False, > blank=False) > > and a simple view that get a parameter from request.GET: > > def view_c3(request): > model_c=SimpleModelC() > model_c.name=request.GET['name'] > model_c.save() > return HttpResponseRedirect("/ok/from/c3/") > > Doing a request to:http://localhost:8000/view_c3/?name=Peter > I get a redirect to '/ok/from/c3/', and in the database: > > SELECT * from myprojects_simplemodelc; > id | name | image_content_type > ----+-------+-------------------- > 7 | Peter | > (1 row) > > Since 'SimpleModelC.image_content_type' is required to be not-null and > not-empty, shouldn't Django check for this before doing the INSERT? > In the database, in 'image_content_type'I get a blank string. > > This is happening me with Django 1.0.2 and the development version of > Django 1.1. > > Thanks in advance! > Horacio
No, the docs are clear on this: "If a field has blank=True, validation on Django’s admin site will allow entry of an empty value. If a field has blank=False, the field will be required." (http://docs.djangoproject.com/en/dev/ref/models/ fields/#blank) The key phrase is *on Django's admin site* (although it's true of ModelForms generally). blank=False is only validated through forms, not when you create an instance manually. -- DR. --~--~---------~--~----~------------~-------~--~----~ 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 django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---