Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

commited #31

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ class Migration(migrations.Migration):
]

operations = [
migrations.RemoveField(
model_name="auction",
name="image",
),
# migrations.RemoveField(
# model_name="auction",
# name="image",
#),
migrations.AddField(
model_name="auction",
name="state",
Expand Down
19 changes: 19 additions & 0 deletions core/migrations/0010_alter_auction_winner.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Generated by Django 4.2.11 on 2024-07-01 22:36

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
('core', '0009_remove_auction_image_auction_state_and_more'),
]

operations = [
migrations.AlterField(
model_name='auction',
name='winner',
field=models.ForeignKey(blank=True, help_text='Auction winner', null=True, on_delete=django.db.models.deletion.CASCADE, related_name='auctions_won', to='core.customer'),
),
]
13 changes: 13 additions & 0 deletions core/migrations/0011_add_image_field_to_auction.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Generated by Django 4.2.11 on 2024-07-01 22:50

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('core', '0010_alter_auction_winner'),
]

operations = [
]
1 change: 1 addition & 0 deletions core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ class Auction(models.Model):
related_name="auctions_won",
help_text="Auction winner",
blank=True,
null=True,
)
seller = models.ForeignKey(
Customer,
Expand Down
1 change: 0 additions & 1 deletion core/serializers/auction.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ class Meta:
"price": {"required": True},
"start_date": {"required": True},
"end_date": {"required": True},
"image": {"required": True},
"category": {"required": True},
"state": {"required": True},
"images": {"required": True},
Expand Down
22 changes: 17 additions & 5 deletions core/serializers/bid.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,40 @@
from rest_framework import serializers
from core.models import Bid

from datetime import datetime

class BidSerializer(serializers.ModelSerializer):
class Meta:
model = Bid
fields = "__all__"


class BidCreateSerializer(serializers.ModelSerializer):
auction_start_date = serializers.DateTimeField(source='auction.start_date', read_only=True)
auction_end_date = serializers.DateTimeField(source='auction.end_date', read_only=True)

class Meta:
model = Bid
fields = [
"amount",
"auction",
"auction_start_date",
"auction_end_date",
]
extra_kwargs = {
"amount": {"required": True},
"auction": {"required": True},
}

def validate(self, data):
if data["amount"] < data["auction"].price:

if data["amount"] <= data["auction"].price:
raise serializers.ValidationError(
"El precio tiene que ser mayor al precio actual"
)


if data["auction"].end_date < datetime.now():
raise serializers.ValidationError(
"Price must be higher than the current price"
"No puedes hacer una oferta despues que la subasta termino."
)
return data

return data
2 changes: 1 addition & 1 deletion core/views/auction.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def create(self, request, *args, **kwargs):

images = serializer.validated_data.pop("images")

auction = serializer.save(seller=seller, winner=winner)
auction = serializer.save(seller=seller)

for image in images:
AuctionImage.objects.create(auction=auction, image=image)
Expand Down