Skip to content

Commit

Permalink
Fix serializer
Browse files Browse the repository at this point in the history
  • Loading branch information
Liu233w committed Nov 20, 2021
1 parent cdf7f86 commit 2e53052
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/EventAPI/serializers.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
from rest_framework import serializers
from rest_framework import fields, serializers
from EventAPI.models import Event as eventModels

class EventsSerializer(serializers.ModelSerializer):

eventTaker = fields.SerializerMethodField()
eventType = fields.SerializerMethodField()

def get_eventTaker(self, instance):
return instance.eventBy.eventTakerName if instance.eventBy else None

Expand All @@ -12,5 +15,8 @@ def get_eventType(self, instance):
class Meta:
model = eventModels
fields = ('eventID','eventName','eventInfo','mainVisual','address','venue','isFree','price',
'pastEventLink', 'pastEventPoster', 'recentEventLink', 'recentEventPoster',)
'pastEventLink', 'pastEventPoster', 'recentEventLink', 'recentEventPoster',
# extra fields
'eventTaker', 'eventType',
)

0 comments on commit 2e53052

Please sign in to comment.