mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Save creation user when making a new part via the API
This commit is contained in:
parent
a147ce4284
commit
d51ac2f5c2
@ -126,6 +126,24 @@ class PartList(generics.ListCreateAPIView):
|
||||
|
||||
serializer_class = part_serializers.PartSerializer
|
||||
|
||||
def create(self, request, *args, **kwargs):
|
||||
""" Override the default 'create' behaviour:
|
||||
We wish to save the user who created this part!
|
||||
|
||||
Note: Implementation coped from DRF class CreateModelMixin
|
||||
"""
|
||||
|
||||
serializer = self.get_serializer(data=request.data)
|
||||
serializer.is_valid(raise_exception=True)
|
||||
|
||||
# Record the user who created this Part object
|
||||
part = serializer.save()
|
||||
part.creation_user = request.user
|
||||
part.save()
|
||||
|
||||
headers = self.get_success_headers(serializer.data)
|
||||
return Response(serializer.data, status=status.HTTP_201_CREATED, headers=headers)
|
||||
|
||||
def list(self, request, *args, **kwargs):
|
||||
"""
|
||||
Instead of using the DRF serialiser to LIST,
|
||||
|
Loading…
Reference in New Issue
Block a user