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=[PeopleFlags.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