Skip to content

Commit 355abae

Browse files
authored
se#747 Sort tag-group pairs by group names (#290)
* se#747 Sort tag-group pairs by group names * se#747 Fix sorting for a little
1 parent 3b043de commit 355abae

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

catalog/models.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,9 @@ def exclude_by_products(self, products: Iterable[AbstractProduct]):
253253
.distinct()
254254
)
255255

256+
# @todo #SE747:30m Rm `get_group_tags_pairs`.
257+
# Use `get_grouped_tags -> Dict[Group, List[Tag]]` instead.
258+
# Tags pairs already lead us to errors with groups order.
256259
def get_group_tags_pairs(self) -> List[Tuple[TagGroup, List['Tag']]]:
257260
"""
258261
Return set of group_tag pairs with specific properties.
@@ -279,7 +282,12 @@ def has_only_int_keys(tags: list):
279282
return False
280283
return True
281284

282-
grouped_tags = groupby(self.prefetch_related('group'), key=attrgetter('group'))
285+
grouped_tags = groupby(
286+
self
287+
.prefetch_related('group')
288+
.order_by('group__position', 'group__name'),
289+
key=attrgetter('group')
290+
)
283291
result = []
284292
for group, tags_ in grouped_tags:
285293
tags_ = list(tags_)

0 commit comments

Comments
 (0)