Well you could do a tuple, but really if the programmer doesn't know
what a Bitmask is, they should not be using it. They're by far not a
simple technique, and should only be used by those who understand when
and why they benefit.
On Dec 6, 3:53 pm, "Craig Kimerer" <[EMAIL PROTECTED]> wrote:
> An
Andrew: Thanks, that looks awesome.
The whole BitMaskField(choices=LIST) idea scares me. You must then force
extra knowledge on the user that ordering is important. If programmer Y
decides the list of choices looks better in alphabetical order (or decides
to add a choice in the middle of the lis
Awesome to see some people working on this. I had tried pre-queryset
refactor and It was just not doable witht he fields API. Can't wait to
see the final result of this :)
I'm also agreeing with the API of field = BitMaskField(choices=LIST)
On Dec 6, 10:37 am, Carl Meyer <[EMAIL PROTECTED]> wrot
@Andrew: Thanks! That's precisely the missing piece from my code; if
I get some time to put it all together, I think it'll be a full
solution. My approach uses sets of arbitrary flag values rather than
creating constants for flags, and it's implemented as a normal model
field, which seems a litt
Here's some code we use at Disqus.
def model_bitfield_handler(attr_name, bit_number):
mask = 2**bit_number
def _bit_handler(self, new_val=None):
if new_val is not None:
old_val = (getattr(self, attr_name, 0) or 0)
if new_val:
setattr(self, a
@ Carl:
You can add new syntax for the methods by doing something like this (And
maybe there is a better way to do this, still pretty new to Python)
from django.db.backends.mysql.base import DatabaseWrapper
DatabaseWrapper.operators['is'] = '& %s'
from django.db.models.sql import constants
const
It should be possible to do this entirely external to Django. The one
thing I would suggest is not to require the user to define the value
for each option, handle that internally. Have some sort of class to
encapsulate the public portion of that.
Alex
On Dec 5, 10:53 am, "Mike Axiak" <[EMAIL P
I've written and am using a BitFlagsField, but hadn't yet shared it
since I haven't been able to get the ORM lookup stuff working the way
I want it. I've pasted my code-in-progress at dpaste:
http://dpaste.com/hold/96435/
The current code includes a model BitFlagsField, a form
MultiCheckboxFiel
I seem to be missing something. Why is it that you cannot just write a
BitMaskField yourself outside of Django?
I thought that it might have been that we don't have __any and __all lookup
types, but it seems you can override get_db_prep_lookup in a field, so
that's not an issue.
And if there do s
Unfortunately, Malcolm has shot this down in the past as something
that would be included in Django:
http://groups.google.com/group/django-developers/browse_thread/thread/4cc529b95c9efe20/439e90ed09cbcf2e
Theoretically, you can do this with a Q object, although I have not
tried since Django
I would use this. The one thing I don't see covered in your example is
setting flags. I would look at allowing a list or tuple of integers.
Using your example:
p = Person(name='John Doe', flags=[PeopleFlags.Male,
PeopleFlags.Employed])
- Justin
On Dec 4, 5:16 pm, "Craig Kimerer" <[EMAIL PROTECT
11 matches
Mail list logo