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
MultiCheckboxField, and a MultiCheckboxWidget.  These three components
are tested and work well together for displaying a set of bit flags as
a set of checkboxes in the admin or a ModelForm.

What I haven't yet been able to get working is the full range of ORM
lookups with bitwise AND and OR.  I'd really welcome others' eyes on
this piece, as I'm not the most familiar with the ORM internals.

AFAICT, it's not possible (outside of modifying Django) to redefine
the semantics (or the generated SQL) of the various __ lookup types,
as Craig wants to do (and I also was originally hoping to do).  You
can override get_db_prep_lookup, but that only allows you to mangle
your field values, not change the SQL operators used.  Thus, I think,
Malcolm's recommendation of using a custom Q-like object.  At the
bottom of the dpaste there is some in-progress code trying to make
this work, but I haven't gotten very far with it yet.  I can do
lookups for the presence of a given flag, but I can't yet AND or OR
those lookups together; I wouldn't be surprised if I'm going about it
completely backwards.

Hope this code helps get the ball rolling.  I'd love to see this
available and working really well.  If it's useful I'd be glad to put
this code into Google code and give commit access to interested
others; just mail me if you'd like to do this.

Carl

--~--~---------~--~----~------------~-------~--~----~
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