Skip to content

Instantly share code, notes, and snippets.

View carvalhochris's full-sized avatar

Christopher Carvalho carvalhochris

View GitHub Profile
@carvalhochris
carvalhochris / views.py
Last active February 27, 2023 14:34
Django Rest Viewset sort by pinned, then by year
class WorkViewSet(viewsets.ModelViewSet):
queryset = Work.objects.all()
serializer_class = WorkSerializer
def get_queryset(self):
queryset = Work.objects.order_by('-pinned', '-year')
return queryset
@carvalhochris
carvalhochris / serializers.py
Created February 7, 2023 16:16
The Card links to a thumbnail
class CardSerializer(serializers.ModelSerializer):
title = serializers.CharField()
song = SongSerializer(read_only=True)
thumbnail = HyperlinkedSorlImageField(
'300x300',
options={"crop": "center"},
source='image',
read_only=True
)