如何使用API呼叫发送枚举数据类型,以在Postgres表中添加数据?
我尝试的是:枚举数据类型是使用sqlalchemy core定义的:
event_type_enum = Enum('Telephonic', 'Online meeting', 'Meeting', "Call",
name='event_type_enum')#, create_type=False)
使用此枚举的模型定义为(删除其他属性(:
events = Table("events", metadata,
Column("id", Integer, primary_key=True),
Column("event_type", event_type_enum),
Column("description", String, unique=True))
尝试了卷曲命令:
curl -b cookies.txt -X POST http://localhost:8081/crm/api/v1.0/events_add -d '{"description":"event8", "user_id":2, "event_type":2}' -H 'Content-type:application/json'
也尝试了:
curl -b cookies.txt -X POST http://localhost:8081/crm/api/v1.0/events_add -d '{"description":"event5", "user_id":2, "event_type":"Call"}' -H 'Content-type:application/json'
这两个都提出了不好的要求。到底是如何使用卷曲发送的枚举数据?
curl -b cookies.txt -x post http://localhost:8081/crm/api/api/v1.0/events_add -d'user_id":2," event_type":" call"}'-h'content -type:application/json'
是正确的方法。问题在于,我稍后添加了枚举的第四个值,该值未被识别并给出错误。
当将枚举本身定义为
时,可以设置默认值event_type_enum = Enum('Telephonic', 'Online meeting', 'Meeting', "Call",
name='event_type_enum', default=event_type_enum.enums[2])