いくつかの男のコードに出くわしました
彼はこのようなモデルを持っています
class Country(models.Model):
name = models.CharField(max_length=100)
class TourDate(models.Model):
artist = models.ForeignKey("Artist")
date = models.DateField()
country = models.ForeignKey("Country")
そして、このようにクエリしています
ireland = Country.objects.get(name="Ireland")
artists = Artist.objects.all().extra(select = {
"tourdate_count" : """
SELECT COUNT(*)
FROM sandbox_tourdate
JOIN sandbox_country on sandbox_tourdate.country_id = sandbox_country.id
WHERE sandbox_tourdate.artist_id = sandbox_artist.id
AND sandbox_tourdate.country_id = %d """ % ireland.pk,
}).order_by("-tourdate_count",)
私の質問は、彼が sandbox_tourdate のようなアンダースコアを持っているのに、それがモデル フィールドにない理由です。それはある種の疑似フィールドのように自動的に作成されますか?