I have to querysets. alllists and subscriptionlists
alllists = List.objects.filter(datamode = 'A')
subscriptionlists = Membership.objects.filter(member__id=memberid, datamode='A')
I need a queryset called unsubscriptionlist, which possess all records in alllists except the records in subscription lists. How to achieve this?
How about:
The unsubscriptionlists should be the inverse of subscription lists.
Brian's answer will work as well, though set() will most likely evaluate the query and will take a performance hit in evaluating both sets into memory. This method will keep the lazy initialization until you need the data.
Since Django 1.11, QuerySets have a
difference()
method amongst other new methods. (Source: https://docs.djangoproject.com/en/1.11/releases/1.11/#models)Also see: https://stackoverflow.com/a/45651267/5497962
Well I see two options here.
1. Filter things manually (quite ugly)
2. Just make another query
You should be able to use the set operation difference to help: