How can I call update on Django queryset, that does not write particular value, but modify the value already there, as follows
Entry.objects.filter(pub_date__year=2010).update(count+=1)
How can I achieve that?
You can use F expression from docs:
reporter = Reporters.objects.filter(name='Tintin')
reporter.update(stories_filed=F('stories_filed') + 1)
Try this:
from django.db.models import F
Entry.objects.filter(pub_date__year=2010).update(count=F('count') + 1)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With