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

Allow fields to be None #170

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

greg-finley
Copy link

fields could be None if exclude is provided. Though I guess no way to represent in types that you need one or the other populated.

@sobolevn
Copy link
Member

sobolevn commented Nov 3, 2021

@greg-finley would you mind attaching a link to the DRF docs to this PR, please?

@greg-finley
Copy link
Author

greg-finley commented Nov 3, 2021

@sobolevn sobolevn closed this Nov 3, 2021
@sobolevn sobolevn reopened this Nov 3, 2021
@sobolevn
Copy link
Member

sobolevn commented Nov 3, 2021

Reopened to trigger the CI once again.

@intgr
Copy link
Contributor

intgr commented Nov 3, 2021

My understanding is that fields may be omitted. But that doesn't mean it can be set to None.

Per DRF documentation

class AccountSerializer(serializers.ModelSerializer):
    class Meta:
        model = Account
        exclude = ['users']

There's no fields = None here.

@greg-finley
Copy link
Author

I have code similar to the below. It passes unit tests that the latter will exclude a field and return the other fields.

class AccountSerializer(serializers.ModelSerializer):
    class Meta:
        model = Account
        fields: Optional[Union[Sequence[str], Literal["__all__"]]] = '__all__'

class AccountHideUsersSerializer(AccountSerializer):
    class Meta(AccountSerializer.Meta):
        model = Account
        fields = None
        exclude = ['users']

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants