django add bitwise logics to the filter query

Апрель 9, 2010

Django has a great ORM, but it has some limitations while performing queries, e.g. it does not allow to do bitwise operation. Likely, django’s QuerySet has extra method ( This method allows developers to write raw sql that will be included into the generated by ORM query. The tricky part is that all fields included in that raw sql must present in filter function.
For example:

res.filter(table__flags__isnull=False).extra(where=['NOT ("applicationName_table"."flags" | %s <> "applicationName_table"."flags")' %  condition])

Here we have a datatable with name table with a mask field called flags and an application called applicationName. If there was not filter(table__flags__isnull=False) this query would fail with «applicationName_table».»flags» is unknown column. I could write any lookup expression with this filed that does not affect the result (checking that this filed is not null is quite OK for that).

Hope, this will help you!

posted in Python by dmitko

5 Comments to "django add bitwise logics to the filter query"

  1. freezer wrote:

    thank you !! very useful report!

  2. wrote:

    Uѕing Porter’s Fіve Forces, Nike’s biggest threat іs thе entry of substitute products or services.

    Ҭhe Chinese invented black powder, and rockets propelled Ƅy thіs combination աere used fοr a millennium.

    » The company sees innovation as one of its core organizational competencies.

  3. wrote:

    Online Marketing is like any other business, you gibe somebod something of value in exchange foor money.
    There’s a lot of chpices to choose from, including online sites presenting the top
    10 home based busines pportunities that have proven lucrrative for many people.
    They hire survey firms to conduct market reesearch foor their existing and upcoming products and services and pay generously for views of the people.
    Creating and marketing information products online is another way to generate a
    very lucrative online income.

  4. pusat baju murah wrote:

    However, this is far from the truth as there are several other cheap options at your disposal
    that will make you look superb and at a cheaper cost.

    On the other hand the designer clothes are not always very
    pricey. A� Youu can mix it tto make heavy, medium or llight starch.
    Since you can’t try anything on you won’t be able to determone
    how well they fit.

  5. kamagra wrote:

    whoah this weblog is magnificent i really like studying your posts.

    Keep up the great work! You realize, many people are looking round for this info, you could aid them greatly.

Powered by Wordpress and MySQL. Theme by Shlomi Noach,