How to convert a list in to queryset django

前端 未结 4 665
盖世英雄少女心
盖世英雄少女心 2021-02-04 09:27

I have a queryset(which is filtered actually) as below

posts = [, , , , 

        
4条回答
  •  情深已故
    2021-02-04 09:45

    Actually i had found one way by googling, but this may take a lot of time for querying/generating results if there are huge number of records

    custom_list = [rec.id for rec in posts if 'string_or_field' in rec.tags.all()]
    
    querset = MyModel.objects.filter(id__in=custom_list)
    

提交回复
热议问题