Django calling save on a QuerySet object - 'QuerySet' object has no attribute 'save'

You'll want to use the update method since you're dealing with multiple objects:

https://docs.djangoproject.com/en/2.0/topics/db/queries/#updating-multiple-objects-at-once


filter returns a queryset. A queryset isn't a single object, it's a group of objects so it doesn't make sense to call save() on a queryset. Instead you save each individual object IN the queryset:

game_participants = GameParticipant.objects.filter(player=player, game=game)
for object in game_participants:
    object.save()

It is possible to get this error by assigning not saved object to another object foreign field.

    for project in projects:
        project.day = day
    day.save()

and the right way of this is:

    day.save()
    for project in projects:
        project.day = day

Tags:

Python

Django