With these models:
class Categoria(models.Model):
titolo=models.CharField(max_length=128, default="unavailable")
class Oggetto(models.Model):
titolo=models.CharField(max_length=128)
desc=models.TextField()
url_img=models.URLField()
id_categoria=models.ForeignKey(Categoria,on_delete=models.CASCADE,related_name="categoria", default=False)
I try this :
qs=Oggetto.objects.filter(id=12).select_related().values()
to have a SQL :
SELECT Oggetto.*,Categoria.titolo FROM Oggetto INNER JOIN Categoria ON (Oggetto.id_categoria=Categoria.id) WHERE Oggetto.id=12
The output (wrong) is :
QuerySet [{'id': 12, 'titolo': 'abc', 'desc': 'abc', 'url_img': '', 'id_categoria_id': 1}]
question from:
https://stackoverflow.com/questions/66064855/django-query-with-inner-join 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…