Skip to content

Commit

Permalink
fix: another try at casting
Browse files Browse the repository at this point in the history
  • Loading branch information
narenaryan committed Apr 9, 2023
1 parent 303bf0b commit 59356c5
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions promptbook/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,11 @@ def search(request):
@login_required(login_url='/login/')
def activity_stream(request):
# This version properly type casts SQL queries to SQLite, PostgreSQL databases
public_prompts = Prompt.objects.filter(is_public=True).annotate(id_as_integer=Cast('id', IntegerField()))
actions = Action.objects.filter(
Q(target_object_id__in=public_prompts.values_list('id_as_integer', flat=True), target_content_type=ContentType.objects.get_for_model(Prompt)),
public_prompts = Prompt.objects.filter(is_public=True)
actions = Action.objects.annotate(
target_object_id_as_integer=Cast('target_object_id', IntegerField())
).filter(
Q(target_object_id_as_integer__in=public_prompts.values_list('id', flat=True), target_content_type=ContentType.objects.get_for_model(Prompt)),
Q(verb="created") | Q(verb="made public")
)

Expand Down

0 comments on commit 59356c5

Please sign in to comment.