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 TextField
and a CharField
is negligible with PostgreSQL. I'm relativly new to Django, and was considering using a TextField
for variable length urls in my database. I was wondering if there are any advantages to using the URLField
? Would it be considered bad form to use a TextField
rather than a URLField
for urls?
相关问题
- Django __str__ returned non-string (type NoneType)
- Django & Amazon SES SMTP. Cannot send email
- Django check user group permissions
- Faster loop: foreach vs some (performance of jsper
- Django restrict pages to certain users
相关文章
- postgresql 关于使用between and 中是字符串的问题
- postgresql 月份差计算问题
- Using boolean expression in order by clause
- TypeError: 'BaseQuery' object is not calla
- Table valued Parameter Equivalent in Postgresql
- Profiling Django with PyCharm
- in redshift postgresql can I skip columns with the
- Why doesn't Django enforce my unique_together
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
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.
https://docs.djangoproject.com/en/dev/ref/models/fields/#urlfield Of course you can use CharField/TextField but handling user input and be sure whatever user enters is up-to you.
From the source code:
If you see the URLField source code you will find it's actually a CharField with URL validator.
Also there is other ready to use fields such as EmailField, ImageField, *Field!
Try this class: