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

How to retrieve a BitField flag value in a queryset filter using values_list. #98

Open
JoabMendes opened this issue Dec 27, 2019 · 2 comments

Comments

@JoabMendes
Copy link

JoabMendes commented Dec 27, 2019

I have a model with BitField like this:

class MyModel(models.Model):
        notifications = BitField(flags=('facebook', 'email'))

I would like to filter my model just retrieving the values, but the BitField is unable to return the flag values independently. I have unsuccessfully tried:

MyModel.objects.all().values_list(
     'id', 'notifications__facebook', 'notification__email'
)

Is there a way to make it work?

@timabbott
Copy link
Collaborator

Note that a bitfield is transmitted over the wire as just a single 32-bit word, and I expect Python to do a similar type of work to make what you're asking for as . So I'm not sure there's an optimization to be had here, though it could simplify code to be able to marshall things that way.

I don't think that syntax makes sense; it would conflict with another field called notifications_facebook. I could imagine e.g. notifications__facebook being valid.

@JoabMendes
Copy link
Author

HI @timabbott I used the __, It was just a typo on my question. I fixed it, but the question is still persisting...

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

No branches or pull requests

2 participants