fixing bug of filter devices
This commit is contained in:
parent
80e74b6d3d
commit
6dc7fb830b
|
@ -24,6 +24,7 @@ from ereuse_devicehub.resources.device.models import Device, Manufacturer, Compu
|
||||||
from ereuse_devicehub.resources.device.search import DeviceSearch
|
from ereuse_devicehub.resources.device.search import DeviceSearch
|
||||||
from ereuse_devicehub.resources.enums import SnapshotSoftware
|
from ereuse_devicehub.resources.enums import SnapshotSoftware
|
||||||
from ereuse_devicehub.resources.lot.models import LotDeviceDescendants
|
from ereuse_devicehub.resources.lot.models import LotDeviceDescendants
|
||||||
|
from ereuse_devicehub.resources.action.models import Trade
|
||||||
from ereuse_devicehub.resources.tag.model import Tag
|
from ereuse_devicehub.resources.tag.model import Tag
|
||||||
|
|
||||||
|
|
||||||
|
@ -150,9 +151,16 @@ class DeviceView(View):
|
||||||
)
|
)
|
||||||
|
|
||||||
def query(self, args):
|
def query(self, args):
|
||||||
query = Device.query.filter().distinct()
|
trades = Trade.query.filter(
|
||||||
# import pdb; pdb.set_trace()
|
(Trade.user_from == g.user) | (Trade.user_to == g.user)
|
||||||
# query = Device.query.filter((Device.owner_id == g.user.id)).distinct()
|
).distinct()
|
||||||
|
|
||||||
|
trades_dev_ids = {d.id for t in trades for d in t.devices}
|
||||||
|
|
||||||
|
query = Device.query.filter(
|
||||||
|
(Device.owner_id == g.user.id) | (Device.id.in_(trades_dev_ids))
|
||||||
|
).distinct()
|
||||||
|
|
||||||
search_p = args.get('search', None)
|
search_p = args.get('search', None)
|
||||||
if search_p:
|
if search_p:
|
||||||
properties = DeviceSearch.properties
|
properties = DeviceSearch.properties
|
||||||
|
|
Reference in New Issue