Django 动态操作model
from django.apps import apps for o in oids_result: oid_result = snmp.snmpWalk(o.oid) if o.model_filed_name and len(o.model_filed_name) > 0: field_name = o.model_filed_name.get('field_name', '') ''' # 动态反射写法 app_name = o.model_filed_name.get('app_name', '') model_name = o.model_filed_name.get('model_name', '') model_obj = apps.get_model(app_name, model_name) ''' if oid_result and len(oid_result): snmp_result = oid_result[0][1] item.__dict__.update({field_name: snmp_result}) item.save() print("snmp结果", oid_result)