2.9.8 Multiple Proxies

One feature of the Model class is that it allows multiple proxies to be attached to the same model, performing automatic notification to all of them. Internally, when a proxy attaches itself to a model, it lets the model know what attributes it is interested in; later, when that attribute changes, the model lets the proxy know. The syntax for using multiple proxies is straightforward; simply create the proxies and attach the same model to them. A small example (NewsForm/newsform4.py) follows:

This example shows some of the power of multiple proxies; as you edit the title you can see the label update immediately. If you look at the lines at the bottom, two proxies are attached to item - a NewsProxy instance, and a NewsLabels instance, which has labels that display the current contents of the model.

This feature can be used in many different ways, and if you create small proxies (that represent a part of the model, instead of the whole model) and embed them in other interfaces you can end up with very dynamic representations of your data. However, it should be noted that there are a few gotchas that you can run into when using multiple Proxies: