2

AssertionError: Expected view blabla to be called with a URL keyword argument named "pk". Fix your URL conf, or set the .lookup_field attribute on the view correctly.

# If you want to use object lookups other than pk, set 'lookup_field'

well I don't want use URL to set pk , I want use pk from query_params for example something like :

request.query_params.get('id', None)

so how setup lookup_field ?

SOLVED it is on update method that we can override pk value

class blabla(generics.CreateAPIView,
            generics.ListAPIView,
            generics.RetrieveAPIView,
            generics.UpdateAPIView):

   def update(self, request, pk = None):
        log.debug("update pk= %s , data = %s" % (pk, str(request.data)))
        pk = request.data.get('id')
        self.kwargs['pk'] = request.data.get('id')
        return super().update(request, pk)
Sérgio
  • 6,966
  • 1
  • 48
  • 53
  • 1
    check this https://stackoverflow.com/questions/38461366/multiple-lookup-fields-for-django-rest-framework – itzMEonTV May 29 '17 at 12:44

1 Answers1

3

Your code doesn't work because you reference to request object on class level, and it is doesn't exists: it is created on instance-level. But you don't need it at all, just make: lookup_field = 'id'

Andrii Rusanov
  • 4,405
  • 2
  • 34
  • 54