ForeignKey field access appears to be lazy evaluated
Hello,
I've implemented a tree-like structure in my model. My items have foreign key fields to the respective left and right neighbor.
If I'm now trying to move an item one position forward it appears that the assigning of neighbors gets messed up.
In my example I have an initial item order like
1 2 3 4
and now i'm trying to move 3 one to the left to get
1 3 2 4
I'm doing this (all inside a commit_on_success transaction) by first removing the moved item, getting
1 2 4
and then (in the same transaction) inserting the moved item to its new position.
1 3 2 4.
But it appears that afterwards item 2 thinks that both its left and right neighbors are item 3.
I have code like this:
item.prevSibling.nextSibling = item.nextSibling # !! (==4) items old prev's next, should be items old next
item.nextSibling.prevSibling = item.prevSibling
item.prevSibling = newPrevSibling
item.nextSibling = newNextSibling # !! (==2) items new next
After staring at this for many hours I have to admit that I'm at a loss!
- I can only speculate that the involved attribute accesses are delays and assignments of old and new values are gettings mixed up.
I tried as first line:
item.prevSibling.nextSibling = ItemModel.objects.get(pk=item.nextSibling.pk)
But that did not make any difference
Any enlightenment would be very welcome.
Thanks,
Sebastian
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home