Skip to content

Commit

Permalink
update DuelSerialzier
Browse files Browse the repository at this point in the history
  • Loading branch information
myslak71 authored and myslak71 committed Feb 7, 2019
1 parent 48bca4e commit 91cfb55
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
19 changes: 11 additions & 8 deletions duels/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,20 @@ class Meta:


class DuelSerializer(serializers.ModelSerializer):
user1 = UserSerializer(read_only=True)
user2 = UserSerializer(read_only=True)
# user2 = serializers.HyperlinkedRelatedField(read_only=True, view_name='siemku')
class Meta:
model = Duel
fields = ('__all__')
read_only_fields = ('user2', 'rounds')

def to_representation(self, instance):
ret = super().to_representation(instance)
if self.context.get('pass_username'):
ret['user1'] = {'id': ret['user1'], 'username': User.objects.get(pk=ret['user1']).username}
ret['user2'] = {'id': ret['user2'], 'username': User.objects.get(pk=ret['user2']).username}
return ret
read_only_fields = ('rounds',)

# def to_representation(self, instance):
# ret = super().to_representation(instance)
# if self.context.get('pass_username'):
# ret['user1'] = {'id': ret['user1'], 'username': User.objects.get(pk=ret['user1']).username}
# ret['user2'] = {'id': ret['user2'], 'username': User.objects.get(pk=ret['user2']).username}
# return ret


class DatasetSerializer(serializers.ModelSerializer):
Expand Down
2 changes: 1 addition & 1 deletion duels/api/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

urlpatterns = [
path('duel/create/', DuelCreateView.as_view()),
path('duel/user/', DuelUserListView.as_view()),
path('duel/user/', DuelUserListView.as_view(), name='siemku'),
path('duel/<pk>', DuelDetailView.as_view()),
path('duel/<pk>/update/', DuelUpdateView.as_view()),
path('duel/<pk>/delete/', DuelDeleteView.as_view()),
Expand Down
1 change: 1 addition & 0 deletions duels/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ class DuelUpdateView(UpdateAPIView):
queryset = Duel.objects.all()
serializer_class = DuelSerializer


def perform_update(self, serializer):
duel = serializer.save()
algorithm = Algorithm.objects.get(pk=self.request.data['algorithm'])
Expand Down

0 comments on commit 91cfb55

Please sign in to comment.