Coverage for api/serializers/base.py: 89%

7 statements  

« prev     ^ index     » next       coverage.py v7.15.2, created at 2026-10-07 06:14 +0000

1from adrf.serializers import ModelSerializer 

2 

3 

4class BaseModelSerializer(ModelSerializer): 

5 """Extends model serializer to use docstring of properties as help text.""" 

6 

7 def build_property_field(self, field_name, model_class): 

8 """ 

9 Use docstrings as the Swagger help text for fields. 

10 

11 This is accomplished by overriding the built-in property field builder. 

12 

13 :param field_name: the name of the property for which the field is being built 

14 :param model_class: the ``class`` instance for the Django model 

15 :return: the Field subclass to use and the keyword arguments to pass to it 

16 """ 

17 

18 klass, kwargs = super().build_property_field(field_name, model_class) 

19 if doc := getattr(model_class, field_name).__doc__: 19 ↛ 21line 19 didn't jump to line 21 because the condition on line 19 was always true

20 kwargs.setdefault("help_text", doc) 

21 return klass, kwargs