Skip to content
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 #15

Closed
ADR-007 opened this issue Mar 27, 2020 · 5 comments
Closed

Annotate SlugRelatedField #15

ADR-007 opened this issue Mar 27, 2020 · 5 comments
Labels
enhancement New feature or request

Comments

@ADR-007
Copy link

ADR-007 commented Mar 27, 2020

Hi!

Is there a way to annotate SlugRelatedField?

@tfranzel
Copy link
Owner

Hey! As these serializer relations are DRF native, i think we should support it. i will prob look at it tomorrow.

@tfranzel tfranzel added the enhancement New feature or request label Mar 27, 2020
@ADR-007
Copy link
Author

ADR-007 commented Mar 27, 2020

Thanks!
Currently, I do like this:

@extend_schema_field(serializers.ChoiceField(Gender))
class GenderSlugRelatedField(serializers.SlugRelatedField):
    def __init__(self, **kwargs):
        super().__init__(slug_field='gender', **kwargs)

@tfranzel
Copy link
Owner

so i added the related serializer fields. A SlugRelatedField is gonna be a simple string though.

I think your usage of the SlugRelatedField with fixed choices is not what it was originally intended for. imho its more like a arbitrary "sluggified" string describing a related object. So you still have to do something custom if you want to have it with a choices enum like that.

@tfranzel
Copy link
Owner

@ADR-007 closing this for now. reopen if you think this does not sufficiently solve the problem.

@ADR-007
Copy link
Author

ADR-007 commented Mar 30, 2020

OK. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants