Skip to content

Commit

Permalink
feat: add price_tag table and routes
Browse files Browse the repository at this point in the history
Linked issue: #611
  • Loading branch information
raphael0202 committed Dec 16, 2024
1 parent c825d2c commit 5574431
Show file tree
Hide file tree
Showing 20 changed files with 830 additions and 20 deletions.
2 changes: 1 addition & 1 deletion open_prices/api/prices/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from open_prices.locations.models import Location
from open_prices.prices.models import Price
from open_prices.products.models import Product
from open_prices.proofs.models import Proof
from open_prices.proofs.models.proof import Proof


class PriceSerializer(serializers.ModelSerializer):
Expand Down
2 changes: 1 addition & 1 deletion open_prices/api/prices/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from open_prices.products.models import Product
from open_prices.proofs import constants as proof_constants
from open_prices.proofs.factories import ProofFactory
from open_prices.proofs.models import Proof
from open_prices.proofs.models.proof import Proof
from open_prices.users.factories import SessionFactory

PRICE_8001505005707 = {
Expand Down
9 changes: 8 additions & 1 deletion open_prices/api/proofs/filters.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import django_filters

from open_prices.proofs.models import Proof
from open_prices.proofs.models.proof import Proof


class ProofFilter(django_filters.FilterSet):
Expand Down Expand Up @@ -38,3 +38,10 @@ class Meta:
"owner",
"price_count",
]


class PriceTagFilter(django_filters.FilterSet):
status__isnull = django_filters.BooleanFilter(
field_name="status", lookup_expr="isnull"
)
status = django_filters.CharFilter(field_name="status", lookup_expr="exact")
43 changes: 42 additions & 1 deletion open_prices/api/proofs/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

from open_prices.api.locations.serializers import LocationSerializer
from open_prices.locations.models import Location
from open_prices.proofs.models import Proof, ProofPrediction
from open_prices.prices.models import Price
from open_prices.proofs.models.price_tag import PriceTag
from open_prices.proofs.models.proof import Proof, ProofPrediction


class ProofPredictionSerializer(serializers.ModelSerializer):
Expand Down Expand Up @@ -81,3 +83,42 @@ class ProofProcessWithGeminiSerializer(serializers.Serializer):
mode = (
serializers.CharField()
) # TODO: this mode param should be used to select the prompt to execute, unimplemented for now


class PriceTagSerializer(serializers.ModelSerializer):
price_id = serializers.PrimaryKeyRelatedField(read_only=True)

class Meta:
model = PriceTag
exclude = ["price", "proof"]


class PriceTagFullSerializer(PriceTagSerializer):
proof = ProofSerializer()

class Meta:
model = PriceTag
exclude = ["price"]


class PriceTagCreateSerializer(serializers.ModelSerializer):
proof_id = serializers.PrimaryKeyRelatedField(
queryset=Proof.objects.all(), source="proof"
)
price_id = serializers.PrimaryKeyRelatedField(
queryset=Price.objects.all(), source="price", required=False
)

class Meta:
model = PriceTag
fields = PriceTag.CREATE_FIELDS


class PriceTagUpdateSerializer(serializers.ModelSerializer):
price_id = serializers.PrimaryKeyRelatedField(
queryset=Price.objects.all(), source="price"
)

class Meta:
model = PriceTag
fields = PriceTag.UPDATE_FIELDS
Loading

0 comments on commit 5574431

Please sign in to comment.