Opened 9 years ago

Closed 9 years ago

Last modified 9 years ago

#10721 closed (invalid)

Django not update field when I use arrays[] for select object:

Reported by: moizes.m@… Owned by: nobody
Component: Database layer (models, ORM) Version: 1.0
Severity: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description (last modified by Karen Tracey)

Django not update field when I use arrays[] for select object:

Itensvar = Itens.objects.all()
Itensvar[0].desc = 'Test'

#django not execute update in database

Change History (3)

comment:1 Changed 9 years ago by anonymous

comment:2 Changed 9 years ago by Karen Tracey

Description: modified (diff)
Resolution: invalid
Status: newclosed

Reformatted description -- please use preview to ensure your tickets are readable before submitting them.

Actually the Itensvar[0].save() will issue a database update, the problem is it will call save() on an newly-retrieved-from-the-database object, not the one you retrieved and change the desc on in the previous line. There is no caching done when you access a queryset by indexing like this. If you look at the doc here: and replace the indexing notation with what its rough equivalent is:

Itensvar[0:1].get().desc = 'Test'

you can see the problem. The 2nd line isn't operating on the same object as the first one changed, it's calling save() on a new copy retrieved from the database. You need to write this as:

x = Itensvar[0]
x.desc = 'Test'

comment:3 Changed 9 years ago by anonymous

Ok, it worked!!, thank's!

Note: See TracTickets for help on using tickets.
Back to Top