0

I have a list of objects called checkins that lists all the times a user has checked into something and another set of objects called flagged_checkins that is certain checkins that the user has flagged. They both reference a 3rd table called with a location_id

I'd like to take the two lists of objects, and remove any of the checkins which have a location_id in flagged_checkins

How do I compare these sets and remove the rows from 'checkins'

Brenden
  • 8,264
  • 14
  • 48
  • 78

2 Answers2

0

As per this SO question,

checkins.objects.filter( location_id__in = list(flagged_checkins.objects.values_list('location_id', flat=True)) ).delete()
Community
  • 1
  • 1
thatwasbrilliant
  • 511
  • 4
  • 11
0

If you are talking about a queryset then, you can definitely try:

checkins.objects.exclude( location_id__in = list(flagged_checkins.objects.values_list('location_id', flat=True)) )

This would remove the objects based on your criteria. But not from the db level.

Sandip Agarwal
  • 1,890
  • 5
  • 28
  • 42