Reputation: 41
I need a little help with a Django Q query im trying to string together, it looks right, but its not quite working. The query is
( Q(src__lte=4) & Q(src__startswith='2') ) |
( Q(src__gt=4) & ~Q(src__istartswith='713') & ~Q(src__istartswith='281') ) )
what im trying to accomplish would be "select where src is less than 4 AND startsiwth 2 OR src is greater than 4 and DOES NOT start with 713 OR 281"
the result is showing src's that start with 713 and 281, what am i doing wrong here? thanks.
Upvotes: 1
Views: 358
Reputation: 10929
it seems that you are mixing type. is src an int or a string? be consistant.
Upvotes: 2
Reputation: 3003
You forgot to put a bracket,
-->> ( <<-- (Q(src__lte=4) & Q(src__startswith='2')) | (Q(src__gt=4) & ~Q(src__istartswith='713') & ~Q(src__istartswith='281')))
either you have to remove the last one.
Or you didn't paste the entire line..
You may want to try this:
(Q(src__gt=4) & !(Q(src__startswith=u'713') | Q(src__startswith=u'281'))
What type of data is your 'src'? Integer or String?
Upvotes: 0