code: def bulk(self, request, *args, **kwargs):
          
          manager = self.get_manager()
          errors = {}
          preferences = []
          payload = request.data
  
          # first, we check updated preferences actually exists in the registry
          try:
              for identifier, value in payload.items():
                  try:
                      preferences.append(
                          self.queryset.model.registry.get(identifier))
                  except exceptions.NotFoundInRegistry:
                      errors[identifier] = 'invalid preference'
          except (TypeError, AttributeError):
              return Response('invalid payload', status=400)
  
          if errors:
              return Response(errors, status=400)
  
          # now, we generate an optimized Q objects to retrieve all matching
          # preferences at once from database
          queries = [
              Q(section=p.section.name, name=p.name)
              for p in preferences
          ]
  
          query = queries[0]
          for q in queries[1:]:
              query |= q
          preferences_qs = self.get_queryset().filter(query)
  
          # next, we generate a serializer for each database preference
          serializer_objects = []
          for p in preferences_qs:
              s = self.get_serializer_class()(
                  p, data={'value': payload[p.preference.identifier()]})
              serializer_objects.append(s)
  
          validation_errors = {}
  
          # we check if any serializer is invalid
          for s in serializer_objects:
              if s.is_valid():
                  continue
              validation_errors[s.instance.preference.identifier()] = s.errors
  
          if validation_errors:
              return Response(validation_errors, status=400)
  
          for s in serializer_objects:
              s.save()
  
          return Response(
              [s.data for s in serializer_objects],
              status=200,
          )
docs: Update multiple preferences at once
  
          this is a long method because we ensure everything is valid
          before actually persisting the changes