def post(self, request, *args, **kwargs): serializer = self.serializer_class(data=request.data, context={'request': request}) serializer.is_valid(raise_exception=True) user = serializer.validated_data['user'] token, created = Token.objects.get_or_create(user=user) user_serializer = UserSelectSerializer(instance=user) details = user_serializer.data details.update(token=token.key) return Response(details)
def to_representation(self, instance): self.fields['cashier'] = UserSelectSerializer() self.fields['client'] = ClientSelectSerializer() return super(OrderModelSerializer, self).to_representation(instance)
def to_representation(self, instance): self.fields['category'] = CategorySelectSerializer() self.fields['creator'] = UserSelectSerializer() return super(ProductModelSerializer, self).to_representation(instance)
def to_representation(self, instance): self.fields['creator'] = UserSelectSerializer() self.fields['product'] = ProductSelectSerializer() return super(SoldCostModelSerializer, self).to_representation(instance)
def to_representation(self, instance): self.fields['client'] = ClientSelectSerializer() self.fields['stock'] = StockSelectSerializer() self.fields['created_by'] = UserSelectSerializer() return super(TransactionModelSerializer, self).to_representation(instance)