Re: BitmaskField

2008-12-07 Thread David Cramer
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

Re: BitmaskField

2008-12-06 Thread Craig Kimerer
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

Re: BitmaskField

2008-12-06 Thread David Cramer
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

Re: BitmaskField

2008-12-06 Thread Carl Meyer
@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

Re: BitmaskField

2008-12-05 Thread ab
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

Re: BitmaskField

2008-12-05 Thread Craig Kimerer
@ 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

Re: BitmaskField

2008-12-05 Thread alex.gay...@gmail.com
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

Re: BitmaskField

2008-12-05 Thread Carl Meyer
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

Re: BitmaskField

2008-12-05 Thread Mike Axiak
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

Re: BitmaskField

2008-12-05 Thread George Vilches
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

Re: BitmaskField

2008-12-05 Thread [EMAIL PROTECTED]
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