Skip to content

Instantly share code, notes, and snippets.

@kezabelle
Created November 29, 2019 12:39
Show Gist options
  • Save kezabelle/60b258802e4eaf6ae798123126de6a8d to your computer and use it in GitHub Desktop.
Save kezabelle/60b258802e4eaf6ae798123126de6a8d to your computer and use it in GitHub Desktop.
for thnee in #django IRC
# Given this doesn't work
qs = Song.objects
qs = qs.prefetch_related(
db.models.Prefetch(
"releases", queryset=SongRelease.objects.raw(
"""
SELECT id, target FROM tungsten_song_release;
"""
),
)
# why not do?
class PartialSongRelease(models.Model):
id = models.WhateverField(primary_key=True)
target = models.WhateverField(...)
class Meta:
managed = False
db_table = "tungsten_song_release"
Song.objects.prefetch_related(Prefetch("releases", queryset=PartialSongRelease.objects.all()))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment