Django model views | How to Update objects from id_parameter to last, and increment 1 to value?

StackOverflow https://stackoverflow.com/questions/21213158

  •  29-09-2022
  •  | 
  •  

Question

Django model views | How to Update objects from id_parameter to last, and increment 1 to value ?

def view_update():
    car.objects.filter(from id to last).update(field=+1) # or delete

how i can do , "from id to last"?

thanks.

Was it helpful?

Solution

Use id__gte=.. argument. And use F() query expression to update:

from django.db.models import F

Car.objects.filter(id__gte=id_parameter).update(F('field') + 1)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top