I'm not quite sure if I got it right, but I believe that the correct is to "create" the object first. Doesn't make to much sense handle an object that is not yet persisted into the database. If you want the data, you could get it with:
data_to_be_saved = self.request.data or, even better: data_to_be_saved = serializer.validated_data Take a look at this: https://github.com/encode/django-rest-framework/issues/2207 Also, take a look here for the CreateModelMixin: http://www.cdrf.co/3.7/rest_framework.viewsets/ModelViewSet.html Hope it helps, somehow. Regards! 2018-05-14 15:26 GMT-03:00 Oliver Zhou <[email protected]>: > I'm trying to do some custom activities in a ModelViewSet > 'perform_create', and I was wondering what the best way to convert > request.data URLs into objects. > > for example > { > "Example": "http://localhost:8000/rest/example/30/", > } > > How can I convert the string there into an object without going into the > serializer? > > i.e., : > > class ConnectionViewSet(viewsets.ModelViewSet): > queryset = Connection.objects.all() > serializer_class = ConnectionSerializer > > def perform_create(self, serializer): > * # how do I get the specific example object here from the URL > passed in* > example_object.do_something() > instance = serializer.save() > > -- > You received this message because you are subscribed to the Google Groups > "Django REST framework" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "Django REST framework" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
