I have a ModelViewSet with create() method overwritten as I may be creating more than one instance at a time. I was wondering if it is possible to perform a get_or_create instead of .perform_create() as seen below?
Essentially if I make the same call twice I would only like the first call to create the instance/s.
class CreateTokenView(viewsets.ModelViewSet):
queryset = BayAccessToken.objects.all()
serializer_class = accessTokenSerializer
def create(self, request, *args, **kwargs):
serializer = self.get_serializer(data=request.data, many=True)
serializer.is_valid(raise_exception=True)
self.perform_create(serializer)
Or is the best option to just loop through and perform own get_or_create on data?