bring back meta choice options lost in upgrade

* status and launch_type OPTIONS choices were lost in the django + drf
upgrade. This brings them back.
This commit is contained in:
Chris Meyers
2016-02-19 14:46:19 -05:00
parent 30633cc82e
commit d70615efbd
3 changed files with 53 additions and 0 deletions

View File

@@ -331,7 +331,22 @@ 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.
#
# This logic is to force rendering choice's on an uneditable field.
# Note: Consider expanding this rendering for more than just choices fields
# Note: This logic works in conjuction with
if hasattr(model_field, 'choices') and model_field.choices:
was_editable = model_field.editable
model_field.editable = True
field_class, field_kwargs = super(BaseSerializer, self).build_standard_field(field_name, model_field)
if hasattr(model_field, 'choices') and model_field.choices:
model_field.editable = was_editable
if was_editable is False:
field_kwargs['read_only'] = True
# Update help text for common fields.
opts = self.Meta.model._meta.concrete_model._meta