summaryrefslogtreecommitdiff
path: root/ishtar_common
diff options
context:
space:
mode:
Diffstat (limited to 'ishtar_common')
-rw-r--r--ishtar_common/models.py10
1 files changed, 8 insertions, 2 deletions
diff --git a/ishtar_common/models.py b/ishtar_common/models.py
index 9b446ff9e..b804739ad 100644
--- a/ishtar_common/models.py
+++ b/ishtar_common/models.py
@@ -5021,7 +5021,13 @@ class Basket(FullSearch, OwnPerms, ValueGetter, TemplateItem):
:param ishtaruser: if provided an alternate user is used
:return: the new basket
"""
- items = list(self.items.all())
+ items = []
+ through = self.items.through
+ basket_pk = "{}_id".format(self.SLUG)
+ item_pk = "{}_id".format(self.items.model.SLUG)
+ q = through.objects.filter(**{basket_pk: self.pk})
+ for r in q.values("pk", item_pk).order_by("pk").all():
+ items.append(r[item_pk])
new_item = self
new_item.pk = None
if ishtaruser:
@@ -5034,7 +5040,7 @@ class Basket(FullSearch, OwnPerms, ValueGetter, TemplateItem):
new_item.label = label
new_item.save()
for item in items:
- new_item.items.add(item)
+ through.objects.create(**{basket_pk: new_item.pk, item_pk: item})
return new_item