Reputation: 389
I currently have two models, Model A and Model B. Within Model A is a column called modules
, and within Model B is a column called new Modules
.
What i want to do is compare the values in new Modules
column against the values in the modules
column in Model A, and return back a list of any values in the new Modules
column that didn't match any value in the modules
column
I'm unable to create a query to do what i want, and was wondering would anyone know how to do this.
Upvotes: 0
Views: 51
Reputation: 25539
modules_a = ModelA.objects.values_list('modules', flat=True).distinct()
modules_b = ModelB.objects.values_list('new_modules', flat=True).distinct()
diff = [i for i in module_b if i not in modules_a]
https://docs.djangoproject.com/en/1.9/ref/models/querysets/#values-list
Upvotes: 1