I’m working on a basic Django app similar to the tutorial. I try to change the value of poll after it’s been created and saved and I can’t. I’ve tried using .commit() in addition to and instead of .save() and that didn’t work either. Here’s what it looks like when I try to change things from the shell. Similar results when through HTML (that is, failure). Any suggestions? I’ve tried changing the attributes of the fields in the models to editable=true which didn’t cause any errors but also didn’t help. Any ideas what could be going on here?
>>> from votes.models import polls
>>> polls.objects.all()[2].title
u'best band'
>>> polls.objects.all()[2].title='best album'
>>> polls.objects.all()[2].title
u'best band'
>>> polls.objects.all()[2].title='best album'
>>> polls.objects.all()[2].save()
>>> polls.objects.all()[2].title
u'best band'
Each time you call
polls.objects.all(), you get an array of reconstituted objects from the database – each time you call.all(), it reconstitutes them from the database again for you, creating a new copy. You’re modifying one of these, but not saving the same one you modified.What you’re doing:
What you ought to do: