1 回答

TA貢獻(xiàn)1851條經(jīng)驗(yàn) 獲得超4個(gè)贊
您可以重寫您的視圖perform_create()
方法,如文檔中所述(您可能需要稍微滾動(dòng)一下,它位于“保存和刪除掛鉤”部分中:
class PostPlayer(generics.ListCreateAPIView):
? ? queryset = PlayerList.objects.all().order_by('-d_code')
? ? serializer_class = PlayerListSerializer
? ? def get(self, request, *args, **kwargs):
? ? ? ? d_code = request.data.get('h_code') + 'test'
? ? ? ? print(d_code)
? ? ...
? ? ...
? ? def perform_create(self, serializer):
? ? ? ? d_code = request.data.get('h_code') + 'test'
? ? ? ? #do something with d_code
? ? ? ? new_code = d_code + 'someSampleValue'
? ? ? ? serializer.save(d_code=new_code)
添加回答
舉報(bào)