Issue
i am writing an API in python django rest framework and i am stuck at creating a serializer field for an ENUM, how can i create a serializer field for an ENUM field. my model code is:
class Queue(models.Model):
class Meta:
db_table = 'queues'
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False, unique=True)
name = models.CharField(max_length=45)
type = EnumChoiceField(QueueTypes, default=QueueTypes.pending)
date = models.DateTimeField(auto_now=True)
and i am writing a serializer for this model.
class QueueSerializer(serializers.ModelSerializer):
class Meta:
model = Queue
fields = ('__all__')
id = serializers.CharField(read_only=True)
name = serializers.CharField(max_length=45, required=True)
type=?????# what am i supposed to do here?
date = serializers.DateTimeField(read_only=True)
Solution
The EnumChoiceField
extension seems to work fine but does not correctly support the HTML support render of the REST Framework, fields serialized as EnumChoiceField
are not rendered.
Answered By - Hardest
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.