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.

class TSearchVectorField(models.fields.TextField):
"""
This lets Django know how to create a field with the "tsvector" type.
"""
description = "Tsearch Vector"

def db_type(self, connection):
return 'tsvector'


class TSearch(models.Model):
fti = TSearchVectorField()

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

Source

Related Posts

0 comments:

Post a Comment

Leave your thoughts ...
---
If you are having trouble with copy/pasting in comments, you need to sign in or click 'Preview'. For more information about this Firefox bug, see here.

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