Hi everyone!
My models are:
class Game(SlugifyMixin, IGDBIdMixin):
title = models.CharField(max_length=250)
storyline = models.TextField(null=True, blank=True)
summary = models.TextField(null=True, blank=True)
platforms = models.ManyToManyField(
"Platform",
through="GamePlatformRelease",
related_name="games",
blank=True
)
class BaseGameAttribute(SlugifyMixin, IGDBIdMixin):
class Meta:
abstract = True
title = models.CharField(max_length=250)
def __str__(self):
return self.title
class Platform(BaseGameAttribute):
pass
class GamePlatformRelease(models.Model):
game = models.ForeignKey(
Game,
on_delete=models.CASCADE,
related_name="releases"
)
platform = models.ForeignKey(
Platform,
on_delete=models.CASCADE,
related_name="releases"
)
date = models.DateField()
And I try to customize my admin panel:
class GamePlatformReleaseInline(admin.TabularInline):
model = GamePlatformRelease
extra = 1
@admin.register(Game)
class GameAdmin(admin.ModelAdmin):
inlines = (GamePlatformReleaseInline, )
def get_queryset(self, request):
qs = super().get_queryset(request)
return qs.prefetch_related("releases", "releases__platform",)
The problem is redundant queries:
SELECT "games_db_platform"."id",
"games_db_platform"."slug",
"games_db_platform"."igdb_id",
"games_db_platform"."title"
FROM "games_db_platform"
6 similar queries. Duplicated 6 times.
Please help