mirror of
https://github.com/more-tech4-magnum-opus/backend.git
synced 2024-11-29 22:33:43 +03:00
33 lines
838 B
Python
33 lines
838 B
Python
|
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
|
||
|
)
|