Order queryset by alternating value

后端 未结 3 767
余生分开走
余生分开走 2020-12-09 05:27

I have the following model:

class Entry(models.Model):
    name = models.Charfield(max_length=255)
    client = models.Charfield(max_length=255)
3条回答
  •  暖寄归人
    2020-12-09 06:14

    Maybe the following will work, with numpy module

    import numpy
    queryset = Entry.objects.all()
    
    ''' catch the number of distinct Entry considering the client fields '''
    
    queryset_client_entries = Entry.objects.distinct('client')
    
    new_list = list(numpy.resize(queryset_client_entries, queryset.count())) 
    ''' An alternative list of clients depending on the length of queryset '''  
    

提交回复
热议问题