开发者

Django models problem

I have a big proble. I implemented a form which holds various fields, among which EmailFIeld must be OPTIONAL.

Here's the model:

email = models.EmailField(max_length=50,blank=True,default='no@address.spec',
             verbose_name=_('email'), help_text=_('Email'))

But when I do the validation of the form and return a JSON with the possible ero开发者_C百科rrs, I always receive:

{'errors':'Enter a valid e-mail address'}

and I want to be able to leave the email field optional. How can I do that?


As I remembered, default means that this field won't be blank, if user do not delete specified address. So this validation error can be because of .spec, try to replace it with .com. And you can also add null = True in your model and required = False in form class.


If you intitially setup the model with email being required, changing it and running syncdb isn't enough to change the underlying SQL to allow the field to not be required.

If you don't have any important data and can afford to wipe the db, you can run python manage.py flush. That will clear all data and run syncdb from scratch.

The better option, is to run a database migration to update the sql to the django models. By far the most popular option with Django is South. It is a tool that is almost essential to use, this is a good time to add it to your repertoire.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜