# /uri/one/{pk}/
class ModelOneView(generic.View):
def post(self, request, pk): # pk has the same value as below
Model.objects.filter(pk=pk).update(name=request.POST['name'])
return HttpResponse(status=200)
# /uri/two/{pk}/
class ModelTwoView(generic.View):
def post(self, request, pk): # pk has the same value as above
Model.objects.filter(pk=pk).update(bool_field=True)
return HttpResponse(status=200)
I simplified my code a little but basically what I'm doing is that I have two different URIs that both perform some changes on the very same model (not the same field though). The problem here is that my client is calling them both basically the same time.
// script.js in my index.html
function notHealthyForDjango() {
callFirstURI();
callSecondURI();
}
Neither Django nor Client throw any errors at any point, I receive the OK responses. However, the changes I attempt to do with the callFirstURI(); never reach the database. But when I comment out the callSecondURI();
function notHealthyForDjango() {
callFirstURI();
//callSecondURI();
}
Now the call to the first URI works as intended!
How can I solve this problem? I'm using psql, Python 2.7 and Django 1.9. How can I modify my models' fields without the risk of such collisions?
EDIT
I'd like to find a server side solution for the problem, instead of just timing my Client's javascript requests more favorably.