diff --git a/docs/conf.py b/docs/conf.py index b1b4c0a..472d738 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -115,38 +115,41 @@ def project_django_models(app, what, name, obj, options, lines): # pylint: disa # Only look at objects that inherit from Django's base model class if inspect.isclass(obj) and issubclass(obj, models.Model): # Grab the field list from the meta class - fields = obj._meta.get_fields() # pylint: disable=W0212 - - for field in fields: - # If it's a reverse relation, skip it - if isinstance( - field, - ( - models.fields.related.ManyToOneRel, - models.fields.related.ManyToManyRel, - models.fields.related.OneToOneRel, - ), - ): - continue - - # Decode and strip any html out of the field's help text - help_text = strip_tags(field.help_text) if hasattr(field, "help_text") else None - - # Decode and capitalize the verbose name, for use if there isn't - # any help text - verbose_name = field.verbose_name if hasattr(field, "verbose_name") else "" - - if help_text: - # Add the model field to the end of the docstring as a param - # using the help text as the description - lines.append(f":param {field.attname}: {help_text}") - else: - # Add the model field to the end of the docstring as a param - # using the verbose name as the description - lines.append(f":param {field.attname}: {verbose_name}") - - # Add the field's type to the docstring - lines.append(f":type {field.attname}: {field.__class__.__name__}") + try: + fields = obj._meta.get_fields() # pylint: disable=W0212 + + for field in fields: + # If it's a reverse relation, skip it + if isinstance( + field, + ( + models.fields.related.ManyToOneRel, + models.fields.related.ManyToManyRel, + models.fields.related.OneToOneRel, + ), + ): + continue + + # Decode and strip any html out of the field's help text + help_text = strip_tags(field.help_text) if hasattr(field, "help_text") else None + + # Decode and capitalize the verbose name, for use if there isn't + # any help text + verbose_name = field.verbose_name if hasattr(field, "verbose_name") else "" + + if help_text: + # Add the model field to the end of the docstring as a param + # using the help text as the description + lines.append(f":param {field.attname}: {help_text}") + else: + # Add the model field to the end of the docstring as a param + # using the verbose name as the description + lines.append(f":param {field.attname}: {verbose_name}") + + # Add the field's type to the docstring + lines.append(f":type {field.attname}: {field.__class__.__name__}") + except Exception: + pass # Return the extended docstring return lines