From 7e85a0cc37b6586a9efe577ccbcbba604410bd64 Mon Sep 17 00:00:00 2001 From: Stein Magnus Jodal Date: Fri, 26 Apr 2013 21:08:19 +0200 Subject: [PATCH] docs: Add ImmutableObject.copy() example --- docs/api/models.rst | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/docs/api/models.rst b/docs/api/models.rst index 4171acb6..11ec017c 100644 --- a/docs/api/models.rst +++ b/docs/api/models.rst @@ -7,6 +7,21 @@ backends and between the backends and the MPD frontend. All fields are optional and immutable. In other words, they can only be set through the class constructor during instance creation. +If you want to modify a model, use the +:meth:`~mopidy.models.ImmutableObject.copy` method. It accepts keyword +arguments for the parts of the model you want to change, and copies the rest of +the data from the model you call it on. Example:: + + >>> from mopidy.models import Track + >>> track1 = Track(name='Christmas Carol', length=171) + >>> track1 + Track(artists=[], length=171, name='Christmas Carol') + >>> track2 = track1.copy(length=37) + >>> track2 + Track(artists=[], length=37, name='Christmas Carol') + >>> track1 + Track(artists=[], length=171, name='Christmas Carol') + Data model relations ====================