Created
August 21, 2012 20:47
-
-
Save hcarvalhoalves/3419301 to your computer and use it in GitHub Desktop.
Django field for PostgreSQL array
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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