You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm using this library to provide metadata information for a frontend application, one of the field in my model is a simple M2M mapped to "static" table with 15 entries.
For that reason, in the related serializer I decided to use MultiChoiceField
class WasteSerializer(serializers.ModelSerializer):
hp = serializers.MultipleChoiceField(choices=tuple(HP.objects.all().values_list('code', 'descr')), label='Proprietà di pericolo')
def create(self, validated_data):
# custom code to set hp appropriately
class Meta:
model = Waste
fields = '__all__'
Unfortunately the available choices are not rendered in the metadata response, the reason is that drf_auto_endpoint.get_field_dict.GetFieldDict.update_choices_from_serializer only recognize ChoiceField as a field for which choices should be populated
def update_choices_from_serializer(self, rv, field_instance, force=False):
if field_instance.__class__.__name__ != 'ChoiceField' and force is False:
return # --> in my case the field is of type 'MultiChoiceField'
if not hasattr(field_instance, 'choices'):
return
if rv.get('related_endpoint', None) is not None and force is False:
return
rv['type'] = settings.WIDGET_MAPPING['choice']
rv['choices'] = [
{
'label': v,
'value': k,
} for k, v in field_instance.choices.items()
]
For this field the rendered metadata is the following (which is not particularly useful for the frontend)
Thanks for the report and your patience. I will look into the possible fixes for this. Using isinstance instead of relying on __class__.__name__ sounds like it should work but I will have to investigate the Django inheritance scheme for those fields.
I'm using this library to provide metadata information for a frontend application, one of the field in my model is a simple M2M mapped to "static" table with 15 entries.
For that reason, in the related serializer I decided to use MultiChoiceField
Unfortunately the available choices are not rendered in the metadata response, the reason is that
drf_auto_endpoint.get_field_dict.GetFieldDict.update_choices_from_serializer
only recognize ChoiceField as a field for which choices should be populatedFor this field the rendered metadata is the following (which is not particularly useful for the frontend)
Thanks,
Mattia
The text was updated successfully, but these errors were encountered: