title: How to make bulk_updates in Django using Queryset
body: <p>Here I am trying to do bulk updates in Django:</p>
  <blockquote>
  <p>Problem: In a model, there is a column name position whose value
  changes according to the drag and drop of the record position. so I am
  creating the Queryset for that, but not getting the required result, I
  can update the value of the particular id that got dragged but
  according to that need to update further makes little tricky using
  Queryset.</p>
  </blockquote>
  <p>Example:</p>
  <pre><code>id name position
   1 anil    1
   2 ABC     2
   3 XYZ     3
   4 DEF     4
  </code></pre>
  <p>now if I drag id 1 to 4th place then I need to shift else by <strong>position - 1,</strong>
  Like:</p>
  <pre><code>id name position
   2 ABC     1
   3 XYZ     2
   4 DEF     3
   1 anil    4
  </code></pre>
  <p>for this, I was using Queryset of bulk_update but not getting any correct way to do that, please let me know the best way to make update the positions. might be I elaborated on the question too long, but I posted this query thrice, in hope that now I will get the required result.</p>
  <p>The model I am using:</p>
  <pre><code>class Device(models.Model):
      id = models.AutoField(primary_key=True)
      name = models.CharField(max_length=100)
      description = models.CharField(max_length=1000)
      position = models.IntegerField(default=0)
  
      def __str__(self):
          return self.name
  </code></pre>
  <p>View.py:
  This is the View I am creating</p>
  <pre><code>def put(self, request):
      max_len = Device.objects.count()
      ids = int(request.query_params.get('id'))
      temp = ids
      old = int(request.query_params.get('old'))
      new = int(request.query_params.get('new'))
  
      if new == old:
          return Response(&quot;both are equal can't go ahead&quot;)
  
      elif new &gt; max_len:
          return Response(&quot;Invalid Position&quot;)
  
      elif old &lt; new:
          # code for this condition
     
      elif old &gt; new:
          # code for this condition
  </code></pre>
  <p>This is how I was creating this.</p>
  <p>Thanks in Advance</p>