#10721: Django not update field when I use arrays[] for select object:
---------------------------------------------------+------------------------
Reporter: [email protected] | Owner: nobody
Status: closed | Milestone:
Component: Database layer (models, ORM) | Version: 1.0
Resolution: invalid | Keywords:
Stage: Unreviewed | Has_patch: 0
Needs_docs: 0 | Needs_tests: 0
Needs_better_patch: 0 |
---------------------------------------------------+------------------------
Changes (by kmtracey):
* status: new => closed
* resolution: => invalid
Old description:
> Django not update field when I use arrays[] for select object:
>
> Itensvar = Itens.objects.all()
> Itensvar[0].desc = 'Test'
> Itensvar[0].save()
>
> #django not execute update in database
New description:
Django not update field when I use arrays[] for select object:
{{{
Itensvar = Itens.objects.all()
Itensvar[0].desc = 'Test'
Itensvar[0].save()
#django not execute update in database
}}}
Comment:
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:
http://docs.djangoproject.com/en/dev/topics/db/queries/#limiting-querysets
and replace the indexing notation with what its rough equivalent is:
{{{
Itensvar[0:1].get().desc = 'Test'
Itensvar[0:1].get().save()
}}}
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'
x.save()
}}}
--
Ticket URL: <http://code.djangoproject.com/ticket/10721#comment:2>
Django <http://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---