Features: 1) Filter recently viewed products by active status in serializer;
Fixes: 1) Correct default value in `recently_viewed` property to handle cache miss; Extra: 1) Inline simplification of serializer logic for recently viewed products.
This commit is contained in:
parent
ecad0561a5
commit
008ab92f95
2 changed files with 3 additions and 4 deletions
|
|
@ -87,7 +87,7 @@ class User(AbstractUser, NiceModel):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def recently_viewed(self):
|
def recently_viewed(self):
|
||||||
return [] or cache.get(f"user_{self.uuid}_rv")
|
return cache.get(f"user_{self.uuid}_rv", [])
|
||||||
|
|
||||||
def check_token(self, token):
|
def check_token(self, token):
|
||||||
return str(token) == str(self.activation_token)
|
return str(token) == str(self.activation_token)
|
||||||
|
|
|
||||||
|
|
@ -94,9 +94,8 @@ class UserSerializer(ModelSerializer):
|
||||||
Returns a list of serialized ProductSimpleSerializer representations
|
Returns a list of serialized ProductSimpleSerializer representations
|
||||||
for the UUIDs in obj.recently_viewed.
|
for the UUIDs in obj.recently_viewed.
|
||||||
"""
|
"""
|
||||||
queryset = Product.objects.filter(uuid__in=obj.recently_viewed)
|
return ProductSimpleSerializer(Product.objects.filter(uuid__in=obj.recently_viewed, is_active=True),
|
||||||
serializer = ProductSimpleSerializer(queryset, many=True)
|
many=True).data
|
||||||
return serializer.data
|
|
||||||
|
|
||||||
|
|
||||||
class TokenObtainSerializer(Serializer):
|
class TokenObtainSerializer(Serializer):
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue