Good evening,
I would like to ask, if there's a different method to a raw sql query to update items by a certain condition inside my views.py? For example, I know I could do an insert query like this:
models.py
class Person(models.Model):
name = models.CharField()
age = models.IntegerField()
value = models.IntegerField()
views.py
def something(request):
...
qs = Person(name="John Doe", age=34, value=10)
qs.save()
...
Is there a similiar method for updating all "Persons" if they fit a certain condition?
...
qs = Person("UPDATE Person SET value=5 WHERE age < 30") # or something like this
qs.save()
...
Thanks for all your help and advice and a great weekend to all of you!
Person.objects.filter(age__lt=30).update(value=5)