Hi Malcolm, On Jul 4, 3:39 pm, Malcolm Tredinnick <[EMAIL PROTECTED]> wrote: > In the general case, this would be very hard to solve, because you could > have objects in a different process space that also need to be notified.
Ah, I hadn't thought of that. > If you are satisfied with only updating objects in the memory space of > the current process, you could rig something up. It's worth paying a bit > of attention to efficiency here -- only notify those objects that are > really affects -- so here's one possible approach: > > Put an __init__ method on your Model. Remember to call > models.Model.__init__ first to do all the normal initialisation. Then > your __init__ method can register the current TreeNode instance with > some global cache. I'd be tempted to store each node in the cache > referenced by the virtualised path from the root. Then, when > insertChild() finished, it can call some other function which will look > in the cache for every node to the right of the new child and call the > "update yourself" method on that node. This would be O(n) in the number > of nodes in the cache for a naive cache key mapping. If you use a clever > cache storage method so that you easily look up all node to the right of > node N, it would be linear in the number of nodes to the right of the > new node (which is less than the number of nodes in total). Ok, so ideally we could use a cache with some weakref which doesn't keep things from being garbage collected, and just update the cache each time. For this abstraction, at least we don't need to hit the database again in order to update the memory cache, since we know the updated values. > Okay, I've skipped almost all the implementation details here, but > hopefully there's enough clues there to work with. Ask questions if not. Plenty, thanks for your help! I've actually realized that since I don't need to add nodes dynamically, I could just construct them once with the right values. I'll be using this abstraction again though, and I may use this approach in the future. Cheers, Lars --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com 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 -~----------~----~----~----~------~----~------~--~---