chargebee / chargebee-python

Python library for the Chargebee API.
https://apidocs.chargebee.com/docs/api?lang=python
MIT License
40 stars 31 forks source link

Add useful __repr__() methods to Model & Result #22

Open rcoup opened 6 years ago

rcoup commented 6 years ago

Fix for #12

Uses Model.fields[0] by default, but can be overridden via Model.repr_field

eg.

>>> r = chargebee.Subscription.list({})[0]
>>> r
<chargebee.Result: customer;subscription>
>>> r.customer
<chargebee.Customer: id=1mk51RNQdn96z7hT6>
>>> r.subscription
<chargebee.Subscription: id=1mkVvvHQiQMbLBBf>
>>> r.customer.billing_address
<chargebee.BillingAddress: zip=None>
rcoup commented 6 years ago

I went through the models and set repr_field on anything where fields[0] was obviously not useful (eg. last_name), but there might be better options.

vikiuvb commented 6 years ago

@rcoup Thanks for your contributions to our Python API library. We are planning to change repr() to render in the format '<modelName #id at #objectId> JSON: #response'. Will it work for you?

rcoup commented 6 years ago

@vikiuvb can you paste in an example? Feels like the entire JSON is too verbose to put in a repr string?

rcoup commented 5 years ago

has been updated against master ~2.6.4.

Any chance of some attention?

rcoup commented 4 years ago

Updated again against 2.7.1