'django howto use select_related not using local id key
i have made two models where i would like to get them joined on the two name keys.
models.py
class MODELa (models.Model):
......
nameXX = models.CharField(_("name"), max_length=255, primary_key=True)
class MODELb (models.Model):
......
nameYY = models.CharField(_("nameYY"), max_length=255)
FKxx = models.ForeignKey(to=MODELa, on_delete=models.CASCADE, null=True)
views.py
rows = MODELb.objects.all().select_related('FKxx')
using debug toolbar, i can see the join is using the id field
LEFT OUTER JOIN "MODELa"
ON ("MODELb"."FKxx_id" = "MODELa"."nameXX")
How do i set it use the local key nameYY?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
