diff --git a/Common/Utils.py b/Common/Utils.py index b0bdd1b..90a4ee1 100644 --- a/Common/Utils.py +++ b/Common/Utils.py @@ -42,6 +42,9 @@ class Utils(object): def classify(num, all_num, fl=2): return str(round(float(round(float(num) / all_num, fl)) * 100)) + "%" # return str(round(float(round(math.ceil(num) / all_num, fl)) * 100)) + "%" + + def model_to_dict(cls): + return {c.name: getattr(cls, c.name, None) for c in cls.__table__.columns} #获取唯一识别码 def UUID(): diff --git a/apps/drug/views.py b/apps/drug/views.py index 871dbb0..9484206 100644 --- a/apps/drug/views.py +++ b/apps/drug/views.py @@ -128,10 +128,9 @@ def drug_use_retur_list(): @token_auth.login_required def get_drug_info(): bar_code = request.values.get("bar_code") - data_list = BllMedicament().get_bar_code_drug_info(bar_code=bar_code) - if data_list: - data_info = data_list[0] - return jsonify(Utils.true_return(data=Utils.msyql_table_model(data_info))) + data = BllMedicament().findEntity(EntityMedicament.bar_code == bar_code) + if data: + return jsonify(Utils.true_return(data=Utils.model_to_dict(data))) else: return jsonify(Utils.false_return(msg="条码有误"))