Skip to content

Instantly share code, notes, and snippets.

@andreypopp
Created May 20, 2011 14:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andreypopp/983040 to your computer and use it in GitHub Desktop.
Save andreypopp/983040 to your computer and use it in GitHub Desktop.
class PGArrayField(models.Field):
""" Custom field for mapping between postgresql array and python list."""
def __init__(self, element_field, **kwargs):
self.element_field = element_field
models.Field.__init__(self, **kwargs)
def db_type(self, *connection):
return '%s[]' % self.element_field.db_type(*connection)
def to_python(self, value):
# psycopg2 handles arrays with care
return value
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment