Skip to content

Instantly share code, notes, and snippets.

@diffused
Last active December 16, 2015 15:49
Show Gist options
  • Save diffused/5458784 to your computer and use it in GitHub Desktop.
Save diffused/5458784 to your computer and use it in GitHub Desktop.
Postgresql array column types in python peewee orm
from peewee import *
db = PostgresqlDatabase(None)
# custom type for postgres Text[] array column
class TextArrayField(Field):
db_field = 'Text[]'
def db_value(self, value):
return value
def python_value(self, value):
return value
class BaseModel(Model):
class Meta:
database = db
class ProductType(BaseModel):
name = CharField()
sysname = CharField()
class Meta:
db_table = "product_types"
class Product(BaseModel):
name = CharField()
sysname = CharField()
sku = CharField()
# Text[] array column
image_colors_hex = TextArrayField()
product_type = ForeignKeyField(ProductType, related_name="product_type")
class Meta:
db_table = "products"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment