Reputation: 379
I'm trying to run this Queryset in Django to the model LogEntry.
logs_entry = LogEntry.objects.filter(content_type_id = ContentType.objects.get_for_model(Regime).pk, object_id__in = user_regimes.values_list('id', flat = True))
But throws this error: You might need to add explicit type casts.
What kind of cast can I use? to make it works.
Upvotes: 0
Views: 128
Reputation: 6865
You have the problem in this line
user_regimes.values_list('id', flat = True) # <QuerySet [15, 9, 16, 10, 17, 11, 12, 13, 14]>
values_list() returns QuerySet not list
To make it work use list()
function
user_ids = list(user_regimes.values_list('id', flat = True))
# [15, 9, 16, 10, 17, 11, 12, 13, 14]
logs_entry = LogEntry.objects.filter(content_type_id = ContentType.objects.get_for_model(Regime).pk, object_id__in = user_ids)
Upvotes: 1