added get_instances_from_related method for product document

This commit is contained in:
a.gorbunov 2020-01-22 11:23:28 +00:00
parent b9e6df5482
commit 1981b44a10

View File

@ -177,3 +177,12 @@ class ProductDocument(Document):
def get_queryset(self):
return super().get_queryset().published().with_base_related()
def get_instances_from_related(self, related_instance):
"""If related_models is set, define how to retrieve the Product instance(s) from the related model.
The related_models option should be used with caution because it can lead in the index
to the updating of a lot of items.
"""
if isinstance(related_instance, models.ProductType) and hasattr(related_instance, 'product_set'):
return related_instance.product_set().all()