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 PROTECTED]> wrote: > 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 seem to be hurdles in creating your own BitMaskField > (perhaps in syncdb?), then that seems like a limitation in the ORM. Though, > everything else I've tried with the ORM recently has shown it to be very > flexible and I wouldn't expect this to be any different. > > -Mike > > On Fri, Dec 5, 2008 at 10:11 AM, George Vilches <[EMAIL PROTECTED]> wrote: > > > 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... > > > 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 -~----------~----~----~----~------~----~------~--~---