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 1.0 was released.  I definitely have a use for this  
as well, and as can be seen from my original post, every DB engine  
that Django includes a driver for has support for at very least the &  
and | operators.

gav


On Dec 5, 2008, at 8:20 AM, [EMAIL PROTECTED] wrote:

>
> 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 PROTECTED]> wrote:
>> Apologies if this has been asked already and I have missed it in  
>> searching,
>> but is there any interest in taking a patch for a BitmaskField?
>>
>> Given the following (albeit stupid) example to show some usages  
>> that would
>> be nice to have on a bitmask field.  I should note in the examples  
>> below,
>> the names I have chosen I am not sold on, but work well enough to  
>> describe
>> what is going on in this example.
>>
>> class Person(models.Model):
>> name = models.TextField()
>> flags = models.BitmaskField()
>>
>> class PeopleFlags(object):
>> NoFlag = 0
>> Male = 1
>> Female = 2
>> Student = 4
>> Unemployed = 8
>> Employed = 16
>>
>> Example filter API:
>>
>> Finding all unemployed students:
>> Person.objects.filter(flags__all=[PeopleFlags.Unemployed,
>> PeopleFlags.Student])
>>
>> Finding all females who are students or unemployed
>> Person 
>> .objects 
>> .filter(flags__is=PeopleFlags.Female).filter(flags__any=[Peop  
>> leFlags.Student,PeopleFlags.Unemployed])
>>
>> Obviously there are some special cases, like you couldn't use the  
>> same logic
>> if someone wanted to find 'All people with NoFlags'.  By default 0  
>> would
>> have to be special cased for '= 0' instead of '& 0'.
>>
>> I dont have the code currently written, but I am willing to put  
>> some work
>> into it if this is a feature that people (other than me) think  
>> would be
>> useful.
>>
>> Craig
> 

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django developers" group.
To post to this group, send email to django-developers@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to