A Model represents an application data structure which can have observers. The observers are typically subclasses of View, but need not be. Class Model provides mechanisms for attaching and removing observers, and for notifying observers when the Model changes.
A Model can have another Model or Document as a parent. When you call the changed() method of a Model, the call is propagated to its parent, if any. If the Model is ultimately contained in a Document, that Document will then be marked as needing to be saved.
Models are pickleable. The link between a Model and its observers is maintained outside the Model object, so that the observers will not be pickled along with the Model.
- views
- List of objects which are observing this Model. Do not modify this list directly; use the add_view and remove_view methods to add and remove observers.
- add_view(view)
- Adds the given object as an observer of this Model. If the object defines an add_model method, it is called with this Model as argument.
- remove_view(view)
- Removes the given object as an observer of this Model. If the object defines a remove_model method, it is called with this Model as argument.
- notify_views(message = 'model_changed', ...)
- Calls a method of each observer with the same name as the message, passing it any additional arguments.
- changed()
- If the Model is contained in a Document, mark the Document as needing to be saved.
- destroy
- Dissociates the Model from any attached observers, and calls the model_destroyed method of each observer which defines it.