Login

MySQL "Text" Type Model Field

Author:
blackbrrr
Posted:
May 27, 2008
Language:
Python
Version:
.96
Tags:
text db field mysql database custom-field models
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

Comments

romain-hardouin (on August 6, 2008):
<p>Hi,</p> <p>Always use ''.replace() instead of re.sub() when the value to find is not a pattern. Replace method is roughly ten times faster.</p> <p>In your snippet :</p> <pre>value = sub("\n", "", value) </pre> <p>Becomes</p> <pre>value.replace('\n', '') </pre> <p>with regards :-)</p>

#

Please login first before commenting.