Skip to content

Instantly share code, notes, and snippets.

@hcarvalhoalves
Created August 21, 2012 20:47
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 hcarvalhoalves/3419301 to your computer and use it in GitHub Desktop.
Save hcarvalhoalves/3419301 to your computer and use it in GitHub Desktop.
Django field for PostgreSQL array
from django.db import models
class IntegerArrayField(models.Field):
__metaclass__ = models.SubfieldBase
def db_type(self, *args, **kwargs):
return "integer[]"
def get_prep_value(self, value):
if value:
value = map(int, value)
return value
def to_python(self, value):
if value:
value = map(int, value)
return value
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment