I have a class:
class Holiday(ActivitiesBaseClass):
"""Holiday is an activity that involves taking time off work"""
Hotel = models.CharField(max_length=255)
""" Name of hotel """
I can print the class docstring by typing:
print(Holiday.__doc__)
This outputs as:
Holiday is an activity that involves taking time off work
How can I print the docstring for Hotel which is a Class attribute/element?
print(Holiday.Hotel.__doc__)
returns:
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
I've also tried the help()
function to no avail.
Sphinx seems to be able to extract the docstrings of class attributes and include them in readthedocs so I’m hoping there’s a way
Don't think it's possible to add docstring for specific field, but you can use field's help_text
argument instead:
Hotel = models.CharField(max_length=255, help_text="Name of hotel")
Unfortunately, there is currently no such implementation of attribute docstrings in Python. There was a PEP that suggested implementing this functionality, but it was rejected.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With