-
Notifications
You must be signed in to change notification settings - Fork 270
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Annotate SlugRelatedField when field is a UUID #854
Comments
Hi, as I tried to convey in the other issue, the You can override the type of that field by using class TagSerializer(serializers.ModelSerializer):
"""Serializer for Tags"""
workspace = extend_schema_field(field={'oneOf': [{'type': 'string'}, {'type': 'string', 'format': 'uuid'}]})(
serializers.SlugRelatedField(slug_field='uuid', queryset=Workspace.objects.all())
)
tag = serializers.UUIDField(source='uuid', read_only=True)
class Meta (object):
model = Tag
fields = ('workspace', 'tag', 'name') |
I'm having an API making extensive use of the To obtain the correct type for a field, we can handle it similarly to a |
Looking at the doc, I may have been to quick to dismiss. The word slug usually means a string in the context of django, but given this, I think it is reasonable to look further. It seems that I will have a look at this again. |
thx to @StopMotionCuber for the `source.append(field.slug_field)` hint
I think this is actually quite neat, given that @kaimcpheeters @StopMotionCuber I would appreciate if you could test PR #893 |
Treat SlugRelatedField analog to PrimaryKeyRelatedField #854
This is related to Annotate SlugRelatedField but specific to when the field is a UUID.
With the below model example, is it possible to annotate that the SlugRelatedField is a UUID rather than a just a string?
In the workspace view the schema specifies the workspace field to be a UUID
workspace | string <uuid>
In the tag view the schema specifies the workspace field to only be a string (through the SlugRelatedField)
workspace | string
tag | string <uuid>
The text was updated successfully, but these errors were encountered: