docs: Add ImmutableObject.copy() example
This commit is contained in:
parent
1647ea73d1
commit
7e85a0cc37
@ -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
|
and immutable. In other words, they can only be set through the class
|
||||||
constructor during instance creation.
|
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
|
Data model relations
|
||||||
====================
|
====================
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user