1.Models's name is UserRecord.
2.Below is the code of my view.
@login_required
def data(request, page, keyword,strEncode):
current_username = request.user.username
data_s = dosomething() #It takes a long time!!!
UserRecord.objects.get_or_create(user=User.objects.get(username=current_username),MyRecords=keyword) # in order to create unique value
# or use below method
# if not UserRecord.objects.filter(user=User.objects.get(username=current_username),MyRecords=keyword):
# UserRecord.objects.create(user=User.objects.get(username=current_username),MyRecords=keyword)
return JsonResponse(data_s, safe=False)
Requested below URL several times with no interval,something like concurrent threading .
http://127.0.0.1:8000/data/1/test/english/
After this operation done,MyRecords column is populated by duplicate values.
I found something in Django document to use 'with transaction.atomic' to deal with this problem but it did not work.