Skip to content

Commit

Permalink
refactor(Products): API: fix re-add ordering via unique_scans_n. Also…
Browse files Browse the repository at this point in the history
… add other scores. closes #662
  • Loading branch information
raphodn committed Dec 31, 2024
1 parent c07c056 commit 9f6e9b8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion open_prices/api/products/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class ProductViewSet(
serializer_class = ProductFullSerializer
filter_backends = [DjangoFilterBackend, filters.OrderingFilter]
filterset_class = ProductFilter
ordering_fields = Product.COUNT_FIELDS + ["created"]
ordering_fields = Product.OFF_SCORE_FIELDS + Product.COUNT_FIELDS + ["created"]
ordering = ["created"]

@action(detail=False, methods=["GET"], url_path=r"code/(?P<code>\d+)")
Expand Down
6 changes: 6 additions & 0 deletions open_prices/products/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ def with_stats(self):

class Product(models.Model):
ARRAY_FIELDS = ["categories_tags", "brands_tags", "labels_tags"]
OFF_SCORE_FIELDS = [
"nutriscore_grade",
"ecoscore_grade",
"nova_group",
"unique_scans_n",
]
COUNT_FIELDS = ["price_count", "location_count", "user_count", "proof_count"]

code = models.CharField(unique=True)
Expand Down

0 comments on commit 9f6e9b8

Please sign in to comment.