Sqlalchemy/marshmallow single Code table join -


i implementing flask rest api existing database. db contain 1 common table, multiple separate code categories.

id = primary key , tablename = "commoncode"  |id | code_category | codevalue | codedesc ------------------------------------------ |1  |  "season"     |    "1"    | "summer" |2  |  "season"     |    "2"    | "winter" |3  |  "status"     |     "1"   | "success" |4  |  "status"     |     "2"   | "fail" |5  |  "deleted"    |    "y"    | "yes" |6  |  "deleted"    |     "n"   | "no" 

i have many tables referencing "commoncode"

  1. when try reference using code below, return id instead of "code desc" column,

  2. i using marshmallow. if specifying column, itemtypedesc = field_for(commoncode, 'codedesc') object return "<model.xxxx.commoncode object @ 0x00f8d710>.

  3. is there recommended approach implement common code table in sqlalchemy/marshmallow?

.

itemtype = db.column(db.string(2),db.foreignkey('commoncode.codevalue'))   itemtypedesc = db.relationship("commoncode",   primaryjoin="and_(othertable.itemtype==commoncode.codevalue, "               "commoncode.code_category=='season')",   collection_class=attribute_mapped_collection('codedesc')) 


Comments