Skip to content

Commit

Permalink
BuyandSell:fixed apis
Browse files Browse the repository at this point in the history
  • Loading branch information
VIBR0X committed Jul 12, 2023
1 parent 0aa2500 commit 4f1aabe
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
13 changes: 8 additions & 5 deletions buyandsell/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
class ProductSerializer(serializers.ModelSerializer):
user = UserProfileSerializer(read_only=True)
category = serializers.SerializerMethodField()
product_image = serializers.SerializerMethodField()

def get_product_image(self, obj):
return obj.product_image.split(',') if obj.product_image else None


def get_category(self, obj):
return obj.name
Expand All @@ -14,14 +19,12 @@ class Meta:
fields = '__all__'

def create(self, validated_data):
data = self.context["request"].data
validated_data['status'] = True
validated_data['deleted'] = False
validated_data['user'] = self.context['request'].user.profile

str_urls = validated_data['product_image']
str_urls = str_urls.strip(" '")
list_urls = [url.strip(" '") for url in str_urls.split(", ")]
validated_data['product_image'] = list_urls

validated_data['product_image'] = ",".join(data["product_image"]) if 'product_image' in data else ""

if validated_data['action'] == 'giveaway':
validated_data['price'] = 0
Expand Down
1 change: 0 additions & 1 deletion buyandsell/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ def create(self, request):
# request.data['contact_details'] = BuyAndSellViewSet.get_contact_details(userpro)
# request.data['user'] = userpro.id
# print(request.data)
print(request.data)

try:
return super().create(request)
Expand Down

0 comments on commit 4f1aabe

Please sign in to comment.