Im trying to develop a friends module to get more aquainted with django. Now there appeared some very strange behavior i can’t follow. It’s a bit hard to follow i guess, but I would really appreciate some help.
When i instantiate a queryset to update some values django produces the right sqlquery but no data is being updated in my mysql db.
Even if i print the result django tells me the right values which “should” come from the db…but in fact it’s not?
My queries look like the following:
friend_update=Friends.objects.filter(user_me=self.user_id, user_he = friend_id,
permission_he = True,
permission_me = True).update(permission_me=False)
see_friend_update=Friends.objects.filter(user_me=self.user_id, user_he = friend_id,
permission_he = True, permission_me = False)
#Save to DB#
for item in see_friend_update:
item.save()
for i in see_friend_update:
print "user me is %s with id %d permission_me set to %s, user_he is %s with id %d " %\
(i.user_me,i.user_me.id,i.permission_me, i.user_he, i.user_he.id)
### After updating friends permissions, this sets the permission of the counterpart
friend_update_vice_versa = Friend.objects.filter(user_me=friend_id, user_he = self.user_id,
permission_he = True,
permission_me = True).update(permission_he=False)
see_friend_update_vice = Friend.objects.filter(user_me=friend_id, user_he = self.user_id,
permission_he = False, permission_me = True)
for e in see_friend_update_vice:
print "user me is %s with id %d permission_he set to%s, user_he is %s with id %d " % \
(e.user_me,e.user_me.id,e.permission_he, e.user_he, e.user_he.id)
Django gives out the following values:
user me is tester with id 2 permission_me set toFalse (in DB it’s still “True”!), user_he is tester232 with id 1
user me is tester232 with id 1 permission_he set toFalse (in DB it’s still “True”!), user_he is tester with id 2
user me is tester with id 2 permission_me set toFalse(This works really!), user_he is tester232 with id 1
I hope i explained the problem well enough so that following is not too hard…
Okay i figured out what the problem is: it is the caching of the queryset. I still think it is a bug..but this solves the problem:
So it was NOT my silly code i guess….