Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions shop/models/product.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class Availability:
"""
Contains the currently available quantity for a given product and period.
"""

def __init__(self, **kwargs):
"""
:param earliest:
Expand Down Expand Up @@ -70,6 +71,7 @@ class AvailableProductMixin:

The product class must implement a field named ``quantity`` accepting numerical values.
"""

def get_availability(self, request, **kwargs):
"""
Returns the current available quantity for this product.
Expand Down Expand Up @@ -149,6 +151,7 @@ class BaseProductManager(PolymorphicManager):
"""
A base ModelManager for all non-object manipulation needs, mostly statistics and querying.
"""

def select_lookup(self, search_term):
"""
Returning a queryset containing the products matching the declared lookup fields together
Expand Down Expand Up @@ -230,6 +233,7 @@ def product_type(self):
Returns the polymorphic type of the product.
"""
return force_str(self.polymorphic_ctype)

product_type.short_description = _("Product type")

@property
Expand Down Expand Up @@ -353,6 +357,8 @@ def update_search_index(self):
of the product.
"""
documents = elasticsearch_registry.get_documents([ProductModel])
if len(documents) == 0:

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

len(documents) would already evaluate as False, no need to check for comparison to 0

return
if settings.USE_I18N:
for language, _ in settings.LANGUAGES:
try:
Expand All @@ -373,6 +379,7 @@ def invalidate_cache(self):
if shop_app.cache_supporting_wildcard:
cache.delete_pattern('product:{}|*'.format(self.id))


ProductModel = deferred.MaterializedModel(BaseProduct)


Expand Down