Django: Using the ORM to (automatically) create custom database field types

0 Comments

When creating the full text index search layer in Django, I had a little issue when new models were created.

Luckily, it's quite easy to create custom database types in your models.

01.class TSearchVectorField(models.fields.TextField):
02.  """
03.  This lets Django know how to create a field with the "tsvector" type.
04.  """
05.  description = "Tsearch Vector"
06. 
07.  def db_type(self, connection):
08.    return 'tsvector'
09. 
10. 
11.class TSearch(models.Model):
12.  fti = TSearchVectorField()

flock-of-seagals
Elegant, like a flock of Seagals.

Source

 
Copyright © Twig's Tech Tips
Theme by BloggerThemes & TopWPThemes Sponsored by iBlogtoBlog