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

Question about querying #4

Open
plopidou opened this issue Apr 24, 2018 · 3 comments
Open

Question about querying #4

plopidou opened this issue Apr 24, 2018 · 3 comments

Comments

@plopidou
Copy link

plopidou commented Apr 24, 2018

Hi there,

Am seriously thinking about using this bitmask field, because it looks neat. :-)

However, would you have examples about building queries against this field, using filter/get in the ORM?

Many thanks!

@renskiy
Copy link
Owner

renskiy commented Apr 24, 2018

Hi. You know I didn't even think about querying :) But you're right it would be very nice feature.

There is no bitwise lookups in Django though. I'll think about it for a while. Maybe new special lookups will be good solution for this.

@michaeldg
Copy link

Bitwise lookups are undesirable from the database's perspective: Not all RDBMS support bitmask index and if your RDBMS does support it you would need to manually add that index.

The only thing that works well in an index (It works in BTREE and HASH indexes, BTREE is the default in most RDBMS) is an equal lookup on a bitmasked column, so if your bitmasked column is "1 | 4 | 16" the only filter that allows the usage of an index is 'bitmasked_column = 21'. Make sure you keep this in mind if you intend to filter on bigger sets of data.

In my opinion, this project is nice because it neatly adds it to the ORM and the Django admin. I do not want to filter on this field, I just want to get the masks after fetching the data with other filters.

@shlomoa
Copy link

shlomoa commented Dec 4, 2019

Django 3 added support for Choices
Not a bit mask, but getting closer.

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

4 participants