6

I'm trying to create a model to describe a table with an enum field in peewee.

I'm seeing that EnumField was removed from the peewee.py file before the 2.0 version, and I can't find anything in the current docs that outlines how to implement it. Does anyone know if I can just use CharField?

Chris Matta
  • 3,263
  • 3
  • 35
  • 48

2 Answers2

5

Here is a working solution for PostgreSQL:

https://gist.github.com/b1naryth1ef/607e92dc8c1748a06b5d

Mathieu Rodic
  • 6,637
  • 2
  • 43
  • 49
4

there was not an EnumField prior to 2.0, but there are docs on implementing a custom field: http://peewee.readthedocs.org/en/latest/peewee/models.html#creating-a-custom-field

I hope this helps.

coleifer
  • 24,887
  • 6
  • 60
  • 75
  • coleifer should that be part of standard peewee fields? I see `choices` option but if it doesn't validate value. I remember sqlobject used to support such field. – Shekhar Mar 10 '15 at 11:55