Advantages to using URLField over TextField?

后端 未结 3 640
后悔当初
后悔当初 2021-02-03 18:07

As I understand it you should always use a TextField for a variable length string when your using a PostgreSQL database because the speed difference between a

3条回答
  •  太阳男子
    2021-02-03 18:37

    URLField is actually CharField w/ supporting of Regexp-based URL pattern checking and a online validator(which was replaced by a RegEx based validator), you could use TextField if you don't care length-limitation of URL

    from django.core.validators import URLValidator
    
    # in model
    field = models.TextField(validators=[URLValidator()])
    

    Furthermore, using of CharField or TextField depends on whether you want max-length constraint on the field, and which element type is more suitable for editing: textarea or input. On PostgreSQL side, there is no significant difference.

提交回复
热议问题