0

このようにデータベースをフィルタリングしたい。

qs = profile.objects.filter().select_related('profile_detail').select_related('location')

しかし、ここで location は profile_detail モデルの外部キーです。では、どうすればそのクエリを実行できますか

class Location(models.Model):
      place = models.CharField(max_length=128)

 class ProfileDetail(models.Model):
     location = models.ForiegnKey(Location)

  class Profile(models.Model):
      detail = models.ForeignKey(ProfileDetail)
4

1 に答える 1

2

関連する検索クエリ構文を使用できます__

https://docs.djangoproject.com/en/1.10/topics/db/queries/#lookups-that-span-relationships

qs = profile.objects.filter().select_related('detail__location')

そして、そうすべきではdetailありませんprofile_detailProfileあなたのフィールドが呼び出されたのと同じように

于 2016-10-20T10:37:43.987 に答える