Proposal: BitMaskField

131 views
Skip to first unread message

CHI Cheng

unread,
Apr 18, 2014, 3:00:22 PM4/18/14
to django-d...@googlegroups.com
Hi,

Is it possible to add a bitmask field to allow multiple choices for small set of options in lieu of ManyToManyField?

For some cases, ManyToManyField is overkill. e.g. Select several days of week to indicate open days for stores while 7 boolean fields are too frustrated.

Benefits to these cases:
- Simpler database structure as 2 tables less
- Better query performance (no joining tables).

Disqus opened source their implementation ( https://github.com/disqus/django-bitfield ), but it supports neither Python 3 nor 1.7. I hope this field could get official supports.

Syntax draft:

Chi


Russell Keith-Magee

unread,
Apr 18, 2014, 8:06:32 PM4/18/14
to Django Developers

Hi Chi,

It's possible that you may get your request by way of Marc Tamlyn's Kickstarter project - I can't confirm that bitmap fields are specifically on todo list, but there PostgreSQL has some native representation for bit types, so it's possible it might be on his radar.

If it turns out BitField isn't on Marc's list, your proposal sounds reasonable to me. I've only had a quick look at at the implementation, but what I've seen looks sound.

I don't think this needs a full DEP though - it's a minor feature that just needs a ticket.

Yours,
Russ Magee %-)


--
You received this message because you are subscribed to the Google Groups "Django developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-develop...@googlegroups.com.
To post to this group, send email to django-d...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-developers.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/c1447699-8cce-40d4-afd5-f5ade2bc3bd9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

CHI Cheng

unread,
Apr 19, 2014, 3:24:46 AM4/19/14
to django-d...@googlegroups.com
It seems bit-related fields are not on the list (https://www.kickstarter.com/projects/mjtamlyn/improved-postgresql-support-in-django)

I think integer fields should be used as base field instead of bit fields, just like disqus's one.

Reasons:
1. Supports all databases django supported.
2. Better query performance, especially in complex query cases including dozens of conditions (I believe this is main reason disqus made one)
3. Arbitrary number of options is not supported here, ManyToManyField should be used if there are many options.
4. The aim of this this field is providing a simple & fast option for limited set of choices, not mapping another database field type. (Like CommaSeparatedIntegerField and EmailField, actually this field could cover many use cases of CommaSeparatedIntegerField, plus better query performance and aggregate support)

We could even call it ChoiceField to reflect the use and purpose, and hide the bitmask concept used here.

Chi
Reply all
Reply to author
Forward
0 new messages