@@ -49,16 +49,20 @@ class RESTObject:
4949 another. This allows smart updates, if the object allows it.
5050
5151 You can redefine ``_id_attr`` in child classes to specify which attribute
52- must be used as uniq ID. ``None`` means that the object can be updated
52+ must be used as the unique ID. ``None`` means that the object can be updated
5353 without ID in the url.
54+
55+ Likewise, you can define a ``_repr_attr`` in subclasses to specify which
56+ attribute should be added as a human-readable identifier when called in the
57+ object's ``__repr__()`` method.
5458 """
5559
5660 _id_attr : Optional [str ] = "id"
5761 _attrs : Dict [str , Any ]
5862 _created_from_list : bool # Indicates if object was created from a list() action
5963 _module : ModuleType
6064 _parent_attrs : Dict [str , Any ]
61- _short_print_attr : Optional [str ] = None
65+ _repr_attr : Optional [str ] = None
6266 _updated_attrs : Dict [str , Any ]
6367 manager : "RESTManager"
6468
@@ -158,10 +162,19 @@ def pprint(self) -> None:
158162 print (self .pformat ())
159163
160164 def __repr__ (self ) -> str :
165+ name = self .__class__ .__name__
166+
167+ if (self ._id_attr and self ._repr_attr ) and (self ._id_attr != self ._repr_attr ):
168+ return (
169+ f"<{ name } { self ._id_attr } :{ self .get_id ()} "
170+ f"{ self ._repr_attr } :{ getattr (self , self ._repr_attr )} >"
171+ )
161172 if self ._id_attr :
162- return f"<{ self .__class__ .__name__ } { self ._id_attr } :{ self .get_id ()} >"
163- else :
164- return f"<{ self .__class__ .__name__ } >"
173+ return f"<{ name } { self ._id_attr } :{ self .get_id ()} >"
174+ if self ._repr_attr :
175+ return f"<{ name } { self ._repr_attr } :{ getattr (self , self ._repr_attr )} >"
176+
177+ return f"<{ name } >" 165178
166179 def __eq__ (self , other : object ) -> bool :
167180 if not isinstance (other , RESTObject ):
0 commit comments