Hi,
I'm trying to execute a "special" request. The request is based on
multiple OR statement. I create the querysets via objects.filter and, at
the end there is an extra statement. I do not know how to remove this
extra() call because I have to do a concatenation (the || part, in SQL
is a concatenate of 2 fields).
query = SiteEquipment.objects.extra(tables=['sites_site'])
if asset != '':
query |= SiteEquipment.objects.filter(asset__icontains=asset)
if mark_sel != -1:
query |=SiteEquipment.objects.filter(equipment__mark__id=mark_sel)
if eq_sel != -1:
query |= SiteEquipment.objects.filter(equipment__id=eq_sel)
if fqdn != '':
fqdn = '%%' + fqdn + '%%'
query |=SiteEquipment.objects.extra(
where=['equipments_siteequipment.site_id =
equipments_siteequipment.name || sites_site.name ILIKE \'%s\'' % fqdn])
The problem is that the previous code will output (if we only activate
the mark_sel if and the fqdn if):
SELECT equipments_siteequipment.id, equipments_siteequipment.site_id,
equipments_siteequipment.equipment_id, equipments_siteequipment.name,
equipments_siteequipment.asset
FROM equipments_siteequipment INNER JOIN equipments_equipment AS
equipments_siteequipment__equipment ON
equipments_siteequipment.equipment_id=equipments_siteequipment__equipment.id,
sites_site
WHERE equipments_siteequipment.site_id = sites_site.id AND
equipments_siteequipment.name || sites_site.name ILIKE '%RTR2%' AND
((equipments_siteequipment__equipment.mark_id = 1))
As you can see (in red) the 2 queries are ANDed but I wrote |=. My whish
is that the red AND should be an OR.
I don't especially wan to use an extra, if you have any idea about howto
do a concatenation with filter, please tell me.
TIA.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---