mirror of
https://github.com/more-tech4-magnum-opus/backend.git
synced 2024-11-24 20:33:42 +03:00
29 lines
733 B
Python
29 lines
733 B
Python
from rest_framework import serializers
|
|
|
|
from marketplace.models import Product
|
|
|
|
|
|
class ProductSerializer(serializers.ModelSerializer):
|
|
class Meta:
|
|
model = Product
|
|
fields = [
|
|
"name",
|
|
"slug",
|
|
"description",
|
|
"image",
|
|
"image_cropped",
|
|
"price",
|
|
"creator",
|
|
]
|
|
extra_kwargs = {
|
|
"image": {"write_only": True},
|
|
"slug": {"read_only": True},
|
|
"image_cropped": {"read_only": True},
|
|
"creator": {"read_only": True},
|
|
}
|
|
|
|
def create(self, validated_data):
|
|
return Product.objects.create(
|
|
**validated_data, creator=self.context["request"].user
|
|
)
|