-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #273 from jenslauterbach/api-speakers
Add Initial Speakers Endpoint
- Loading branch information
Showing
3 changed files
with
46 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
from rest_framework import serializers, viewsets | ||
|
||
from speaker.models import Speaker | ||
|
||
|
||
class SpeakerSerializer(serializers.HyperlinkedModelSerializer): | ||
id = serializers.CharField(source="slug") | ||
image = serializers.ImageField(source="public_image", use_url=True, allow_null=False, allow_empty_file=False) | ||
|
||
class Meta: | ||
model = Speaker | ||
fields = ["id", "url", "name", "short_biography", "position", "image"] | ||
lookup_field = "slug" | ||
extra_kwargs = { | ||
"url": {'lookup_field': 'slug'} | ||
} | ||
|
||
def to_representation(self, instance): | ||
representation = super().to_representation(instance) | ||
|
||
# TODO Jens: This probably can be solved more elegantly with a mixin. | ||
if not representation["image"]: | ||
representation["image"] = "" | ||
|
||
return representation | ||
|
||
|
||
class SpeakerViewSet(viewsets.ReadOnlyModelViewSet): | ||
queryset = Speaker.objects.all() | ||
serializer_class = SpeakerSerializer | ||
lookup_field = "slug" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters