Skip to content

Instantly share code, notes, and snippets.

@db0company
Created May 10, 2014 15:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save db0company/cd1f918497b7246cc468 to your computer and use it in GitHub Desktop.
Save db0company/cd1f918497b7246cc468 to your computer and use it in GitHub Desktop.
class AchievementStatusViewSet(viewsets.ModelViewSet):
queryset = api_models.AchievementStatus.objects.all()
serializer_class = api_serializers.AchievementStatusSerializer
filter_fields = ('achievement', 'status', 'owner')
def create(self, request, pk=None):
type = 'new_objective' if (request.DATA['status'] == 'objective') else 'achievement_unlocked'
activity = api_models.PlayerActivity.objects.create(owner=request.user,
type=type)
activity.achievement_statuses.add(what)
return Response(self.get_serializer().data)
# note: manytomany relations cannot be added during the "create", that's why I use an "add" after
# searching for "what", want the achievement status that has just been created and is about to be returned
# tried:
# self.get_serializer().data, but unhashable type: 'SortedDictWithMetadata'
# pk, but is = None
# request.DATA, but unhashable type: 'QueryDict'
# self.model, but is = None
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment