-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserializers.py
49 lines (33 loc) · 1.22 KB
/
serializers.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
from rest_framework import serializers
from event_app.models import Category, Speaker, Event, Registered
class CategorySerializer(serializers.ModelSerializer):
class Meta:
model = Category
fields = '__all__'
class SpeakersSerializer(serializers.ModelSerializer):
class Meta:
model = Speaker
fields = '__all__'
class RegisteredSerializer(serializers.ModelSerializer):
class Meta:
model = Registered
fields = '__all__'
class EventsSerializer(serializers.ModelSerializer):
class Meta:
model = Event
fields = ['id', 'name', 'photo', 'data']
class EventsDetailSerializer(serializers.ModelSerializer):
people_count = RegisteredSerializer(read_only=True, many=True)
speakers_detail = SpeakersSerializer(read_only=True, many=True)
class Meta:
model = Event
fields = '__all__'
extra_kwargs = {
'user': {'read_only': True}
}
def to_representation(self, instance):
response = super().to_representation(instance)
print(response)
response['last_seats'] = (response['number_for_seats']) - len(response['people_count'])
print(response['last_seats'])
return response