Home > Net >  why model object attribute not change when i try to access it directly without assign to variable
why model object attribute not change when i try to access it directly without assign to variable

Time:04-29

i try here to change title but this not work. enter image description here

but when assign object to variable change is work.

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

CodePudding user response:

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.

  • Related