django models use regular
有時候DB的field無法滿足我們的要求 像是Phone number,有些人會把該欄位定義為char field 不過,又想要電話號碼內不能有除了數字以外的符號 這時候可
在django model下創建field的時候加入
regular作控制
sometimes default field type can't implementing what we want , just like phone
number. like phone number,we want it is numbers but can't allow any sign. so when we create table's
then we can create regular under the field
from django.core.validators import RegexValidator class UserProfile(models.Model): tel_regex = RegexValidator(regex='^[0-9]*$', message='wrong phone type') tel = models.CharField('聯絡電話',validators=[tel_regex], max_length=25, default=0)
訂閱:
張貼留言
(
Atom
)
技術提供:Blogger.
沒有留言 :
張貼留言