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
  •  | 
  •  

문제

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.

도움이 되었습니까?

해결책

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)
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top