mirror of
https://github.com/pretix/pretix.git
synced 2026-05-08 15:44:02 +00:00
Devices: Fix bulk edit query (#3541)
This commit is contained in:
@@ -1054,8 +1054,8 @@ class DeviceBulkUpdateView(DeviceQueryMixin, OrganizerDetailViewMixin, Organizer
|
|||||||
limit_events_list=Subquery(
|
limit_events_list=Subquery(
|
||||||
Device.limit_events.through.objects.filter(
|
Device.limit_events.through.objects.filter(
|
||||||
device_id=OuterRef('pk')
|
device_id=OuterRef('pk')
|
||||||
).order_by('device_id', 'event_id').values('device_id').annotate(
|
).order_by().values('device_id').annotate(
|
||||||
g=GroupConcat('event_id', separator=',')
|
g=GroupConcat('event_id', separator=',', ordered=True)
|
||||||
).values('g')
|
).values('g')
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -66,18 +66,26 @@ class GroupConcat(Aggregate):
|
|||||||
function = 'group_concat'
|
function = 'group_concat'
|
||||||
template = '%(function)s(%(field)s, "%(separator)s")'
|
template = '%(function)s(%(field)s, "%(separator)s")'
|
||||||
|
|
||||||
def __init__(self, *expressions, **extra):
|
def __init__(self, *expressions, ordered=False, **extra):
|
||||||
|
self.ordered = ordered
|
||||||
if 'separator' not in extra:
|
if 'separator' not in extra:
|
||||||
# For PostgreSQL separator is an obligatory
|
# For PostgreSQL separator is an obligatory
|
||||||
extra.update({'separator': ','})
|
extra.update({'separator': ','})
|
||||||
super().__init__(*expressions, **extra)
|
super().__init__(*expressions, **extra)
|
||||||
|
|
||||||
def as_postgresql(self, compiler, connection):
|
def as_postgresql(self, compiler, connection):
|
||||||
return super().as_sql(
|
if self.ordered:
|
||||||
compiler, connection,
|
return super().as_sql(
|
||||||
function='string_agg',
|
compiler, connection,
|
||||||
template="%(function)s(%(field)s::text, '%(separator)s')",
|
function='string_agg',
|
||||||
)
|
template="%(function)s(%(field)s::text, '%(separator)s' ORDER BY %(field)s ASC)",
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
return super().as_sql(
|
||||||
|
compiler, connection,
|
||||||
|
function='string_agg',
|
||||||
|
template="%(function)s(%(field)s::text, '%(separator)s')",
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class ReplicaRouter:
|
class ReplicaRouter:
|
||||||
|
|||||||
Reference in New Issue
Block a user