Reputation: 3399
I have a ModelAdmin class, to which I have added a custom action called add_50_credits as follows:
class TutorAdmin(admin.ModelAdmin):
...
actions = ['add_50_credits']
def add_50_credits(self, request, queryset):
queryset.update(account_balance+=50)
What I am trying to do is add 50 to the account_balance of all users in the queryset. However, this code gives a syntax error. How do I get the variable account_balance for each object in the queryset and add 50 to it?
Upvotes: 0
Views: 82
Reputation: 599480
You use F
objects.
from django.db.models import F
queryset.update(account_balance=F('account_balance') + 50)
Upvotes: 2