From e27fde98639550103eee4e2f099c4c42330591c1 Mon Sep 17 00:00:00 2001 From: Jacob Rief Date: Tue, 5 May 2020 01:06:18 +0200 Subject: [PATCH] handle update if thing is queryset --- shop/search/documents.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/shop/search/documents.py b/shop/search/documents.py index 96cf4a231..487a7660d 100644 --- a/shop/search/documents.py +++ b/shop/search/documents.py @@ -59,20 +59,20 @@ def prepare_body(self, instance): body = template.render({'product': instance}) return body - def update(self, product, refresh=None, action='index', parallel=False, **kwargs): - if product.active: - if self._language: - with translation.override(self._language): - super().update(product, refresh=None, action='index', parallel=False, **kwargs) - else: - super().update(product, refresh=None, action='index', parallel=False, **kwargs) - else: + def update(self, thing, refresh=None, action='index', parallel=False, **kwargs): + if isinstance(thing, ProductModel._materialized_model) and thing.active is False: try: - doc = self.get(id=product.id) + doc = self.get(id=thing.id) except NotFoundError: pass else: doc.delete() + else: + if self._language: + with translation.override(self._language): + super().update(thing, refresh=None, action='index', parallel=False, **kwargs) + else: + super().update(thing, refresh=None, action='index', parallel=False, **kwargs) class ProductDocument: