Fix help text in OPTIONS for common, read-only fields. Also fix display of None for foreign key fields in browsable API help.

This commit is contained in:
Chris Church
2016-03-28 18:00:53 -04:00
parent d51f56af9c
commit aedf1d87ab
3 changed files with 22 additions and 25 deletions

View File

@@ -326,7 +326,6 @@ class BaseSerializer(serializers.ModelSerializer):
return obj.active
def build_standard_field(self, field_name, model_field):
# DRF 3.3 serializers.py::build_standard_field() -> utils/field_mapping.py::get_field_kwargs() short circuits
# when a Model's editable field is set to False. The short circuit skips choice rendering.
#
@@ -343,27 +342,6 @@ class BaseSerializer(serializers.ModelSerializer):
if was_editable is False:
field_kwargs['read_only'] = True
# Update help text for common fields.
opts = self.Meta.model._meta.concrete_model._meta
if field_name == 'id':
field_kwargs.setdefault('help_text', 'Database ID for this %s.' % smart_text(opts.verbose_name))
elif field_name == 'name':
field_kwargs['help_text'] = 'Name of this %s.' % smart_text(opts.verbose_name)
elif field_name == 'description':
field_kwargs['help_text'] = 'Optional description of this %s.' % smart_text(opts.verbose_name)
elif field_name == 'type':
field_kwargs['help_text'] = 'Data type for this %s.' % smart_text(opts.verbose_name)
elif field_name == 'url':
field_kwargs['help_text'] = 'URL for this %s.' % smart_text(opts.verbose_name)
elif field_name == 'related':
field_kwargs['help_text'] = 'Data structure with URLs of related resources.'
elif field_name == 'summary_fields':
field_kwargs['help_text'] = 'Data structure with name/description for related resources.'
elif field_name == 'created':
field_kwargs['help_text'] = 'Timestamp when this %s was created.' % smart_text(opts.verbose_name)
elif field_name == 'modified':
field_kwargs['help_text'] = 'Timestamp when this %s was last modified.' % smart_text(opts.verbose_name)
# Pass model field default onto the serializer field if field is not read-only.
if model_field.has_default() and not field_kwargs.get('read_only', False):
field_kwargs['default'] = field_kwargs['initial'] = model_field.get_default()