title: How to latest objects created in django models by similar field value?
body: <p>I have created an app here people can upload 'csv' files of their items details to the server, and then perform various opertaions upon it. But, because every item has it's own unique ID, whenever a csv is uploaded, there is no way to figure out which item-batch was uploaded last.</p>
  <h2>Upload function</h2>
  <p>This is my function in views.py importing the data in the Itembatch model:</p>
  <pre><code>@method_decorator([login_required, teacher_required], name='dispatch')
  class UploadedItems(ListView):
      model = ItemBatch
      ordering = ('name',)
      context_object_name = 'quizzes'
      template_name = 'classroom/teachers/item_list.html'
  
  
  
      def get_queryset (self):
          # queryset = self.request.user.uploaded_by
          print(&quot;----------------&quot; + str(ItemBatch.objects.latest('time')))
          return ItemBatch.objects.filter(uploaded_by=self.request.user)
  </code></pre>
  <p>And this is the model:</p>
  <pre><code># item upload
  class ItemBatch(models.Model):
  
      # uploaded_by = models.ForeignKey(Teacher, on_delete=models.CASCADE, related_name='uploaded_by')
  
      ttypes =(('Open','Open'),('Container','Container'),('Trailer','Trailer'),('All','All'))
      uploaded_by = models.ForeignKey(User, on_delete=models.CASCADE, related_name='uploaded_by')
      name = models.CharField(max_length=30)
      pid = models.CharField(max_length=30)
      quantity = models.CharField(max_length=30)
      length = models.CharField(max_length=100, blank=True)
      width = models.CharField(max_length=100, blank=True)
      height = models.CharField(max_length=100, blank=True)
      volume = models.CharField(max_length=100, blank=True)
      weight = models.CharField(max_length=100, blank=True)
      truck_type = models.CharField(max_length=255,default=0, choices=ttypes)
      origin = models.CharField(max_length=100, blank=True)
      destination = models.CharField(max_length=100, blank=True)
      time = models.DateTimeField(max_length=100, blank=True,default=now)
  
  
      def __str__ (self):
          return self.name
  </code></pre>
  <h2>What I tried</h2>
  <p>As you can see,</p>
  <pre><code>print(&quot;----------------&quot; + str(ItemBatch.objects.latest('time')))
  </code></pre>
  <p>prints only the latest item and not the whole batch which I need. I need a queryset with all the items which were has the same time field and is the latest. Is there any way to do this without using any kind of BatchID in the model ?</p>
  <p>This is my models database:</p>
  <p><a href="https://i.stack.imgur.com/Uwnx7.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Uwnx7.png" alt="1" /></a></p>
  <p>As you can see, I want to segregate/differentiate between different batches of items.</p>