Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I create a model of a table with an enum in peewee 2?

Tags:

python

peewee

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?

like image 772
Chris Matta Avatar asked Dec 17 '12 22:12

Chris Matta


2 Answers

Here is a working solution for PostgreSQL:

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

like image 200
Mathieu Rodic Avatar answered Oct 23 '22 18:10

Mathieu Rodic


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.

like image 42
coleifer Avatar answered Oct 23 '22 18:10

coleifer