backend/app/events/api/serializers.py

33 lines
838 B
Python
Raw Normal View History

2022-10-08 19:31:01 +03:00
from rest_framework import serializers
from events.models import Event
from users.api.serializers import UserSerializer
class EventSerializer(serializers.ModelSerializer):
creator = UserSerializer(many=False, read_only=True)
class Meta:
model = Event
fields = [
"name",
"about",
"slug",
"creator",
"starts",
"image",
"planning",
"attended",
]
extra_kwargs = {
"slug": {"read_only": True},
"creator": {"read_only": True},
"planning": {"read_only": True},
"attended": {"read_only": True},
}
def create(self, validated_data):
return Event.objects.create(
**validated_data, creator=self.context["request"].user
)