In the code below, I've created an endpoint to create a user in the database.
class ClientViewSet(viewsets.ModelViewSet):
serializer_class = ClientSerializer
queryset = Clients.objects.all()
@action(detail=True, methods=["POST"])
def create_client(self, request, pk=None):
Clients.objects.create(client_id=pk, username=Clients.username, password=Clients.password, first_name=Clients.first_name, last_name=Clients.last_name, address=Clients.address)
return Response("User Created", status= status.HTTP_200_OK)
This indeed creates an instance in the the model, but each field contains texts similar to "<django.db.models.query_utils.DeferredAttribute object at 0x7fca8f1d3d50>" instead of the actual values. I used Postman as a tool, and is how I created this instance, if I just use a 'Post' method on the url ../client/ instead of ../client/pk/create_client/ it returns the correct values.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…