我在函数中有一个 ajax 调用
console.log("Executing call on " + link);
$.ajax({
type : "POST",
url : link,
data : {"clientId" : selectedClient, "id" : id},
dataType : "json",
success : function(retData) {
console.log(JSON.parse(retData));
}
})
在views.py中调用:
def putClientPeerData(request):
client = Client.objects.get(client = request.REQUEST["clientId"])
peer = Client.objects.get(client = request.REQUEST["id"])
ClientPeers.objects.create(client = client, parentorg = peer.parentorg, eff_date = datetime.now(), exp_date = None).save()
testPeer = ClientPeers.objects.get(client = client, parentorg = peer.parentorg)
if testPeer.client == client:
return HttpResponse(simplejson.dumps({"returnValue" : "success"}))
else:
return HttpResponse(simplejson.dumps({"returnValue" : "failure"}))
但是,该save
方法执行了两次,导致查询出现MultipleObjectsReturned
异常testPeer
。