'Model object attribute not change without assign to variable

I try here to change title but this not work.

enter image description here

but when assign object to variable, change works.

enter image description here

I need any one explain why it work when I assign object to variable and why not work when access it directly?



Solution 1:[1]

That's because using the slice operator ([0] in this case) will always execute a new query, so none of your changes will be reflected.

That is why your second example where you save the result of project[0] works, because you are preventing the reevaluation of the queryset by saving the result first.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Brian Destura