S
S
Sergey Alekseev2019-07-30 07:38:14
Django
Sergey Alekseev, 2019-07-30 07:38:14

Django, how to process view requests in parallel?

Good afternoon, there is a view - one article and counts of views, if you go to it in parallel, then some views will not be counted. What is the easiest way to fix this?
What is the easiest way to do this?
Code that changes views

article = Article.objects.get(id=kwargs.get('pk'))
article.count += 1
article.save()

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
sim3x, 2019-07-30
@serj2000

https://stackoverflow.com/a/28832804

from django.db.models import F

Video.objects.filter(pk=video.pk).update(views=F('views') + 1)
video.views += 1 # to show valid counter in the template

https://docs.djangoproject.com/en/2.2/ref/models/e...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question