Login

MySQL "Text" Type Model Field

Author:
blackbrrr
Posted:
May 27, 2008
Language:
Python
Version:
.96
Score:
1 (after 1 ratings)

Custom field for using MySQL's text type.

text is more compact than the longtext field that Django assigns for models.TextField (2^16 vs. 2^32, respectively)

1
2
3
4
5
from django.db import models

class NormalTextField(models.Field):		
	def db_type(self):
		return 'text'

More like this

  1. Stuff by NixonDash 1 month ago
  2. Add custom fields to the built-in Group model by jmoppel 3 months ago
  3. Month / Year SelectDateWidget based on django SelectDateWidget by pierreben 6 months, 2 weeks ago
  4. Python Django CRUD Example Tutorial by tuts_station 7 months ago
  5. Browser-native date input field by kytta 8 months, 2 weeks ago

Comments

romain-hardouin (on August 6, 2008):

Hi,

Always use ''.replace() instead of re.sub() when the value to find is not a pattern. Replace method is roughly ten times faster.

In your snippet :

value = sub("\n", "", value)

Becomes

value.replace('\n', '')

with regards :-)

#

Please login first before commenting.