The easiest way would be to slice the list exactly how you were doing with x[3]... It doesn't get much easier than that.
I guess if you really need to spare yourself three keystrokes, you can do it like this: >>> x = YourModel.objects.all()[3] >>> x.foo = 'bar' >>> x.save() Cheers, AT On Fri, Oct 7, 2011 at 6:01 PM, Chris Seberino <[email protected]> wrote: > > > On Oct 7, 10:39 am, Jacob Kaplan-Moss <[email protected]> wrote: > > On Fri, Oct 7, 2011 at 10:30 AM, Chris Seberino <[email protected]> > wrote: > > > > > I've noticed that this doesn't often work in Django shell... > > > > > x = MyModel.objects.all() > > > x[3].some_field = "new value" > > > x[3].save() > > > This is because `MyModel.objects.all()` isn't a list; it's a QuerySet. > > That is, `MyModel.objects.all()` *doesn't* hit the database until you > > say `x[3]`, at which point Django performs a query with a LIMIT and > > OK. I understand. What is easiest way then to *force* my x[3] code > above to hit the database so that > my changes are permanent? > > -- > You received this message because you are subscribed to the Google Groups > "Django users" 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-users?hl=en. > > -- You received this message because you are subscribed to the Google Groups "Django users" 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-users?hl=en.

