How to get the difference of two querysets in Django?

前端 未结 4 1068
一个人的身影
一个人的身影 2020-12-29 04:41

I have to querysets. alllists and subscriptionlists

alllists = List.objects.filter(datamode = \'A\')
subscriptionlists = Membership.objects.filter(member__id         


        
4条回答
  •  青春惊慌失措
    2020-12-29 05:43

    Since Django 1.11, QuerySets have a difference() method amongst other new methods:

    # Capture elements that are in qs_all but not in qs_part
    qs_diff = qs_all.difference(qs_part)    
    

    Also see: https://stackoverflow.com/a/45651267/5497962

提交回复
热议问题