2017-06-23 76 views
0

我有2個數據庫表,Prospects和Profile。他們用一到一個外鍵關係相關如何從Django中的父模型獲取相關數據?

Model.py

class Prospect(models.Model): 
    profile = models.OneToOneField(Profile, on_delete=models.CASCADE, null=True, blank=True, related_name="profile_prospects") 

class Profile(models.Model): 
    user = models.OneToOneField(User, on_delete=models.CASCADE, related_name="profile") 

在我view.py

prospects = prospects[:50] 

我有前景的一個QuerySet(前景工作正確,正是我想要的),並且我想根據上面的數據庫模型檢索配置文件的QuerySet。我試圖

profiles = Profile.objects.filter(profile_prospects__in = prospects) 

它返回的

django.db.utils.ProgrammingError: subquery has too many columns 

錯誤我怎樣才能得到所有相關的配置文件?

+0

你確定這是一個查詢集?還是你在某個時候使用了values()? – Melvyn

回答

0

你有

profiles = Profile.objects.filter(profile_prospects__in = prospects) 
0

對不起空間,我可能會在這裏混淆。但是配置文件自動繼承預期,因爲它是一對一的關係嗎?

當你有前景你應該能夠得到輪廓這樣

prospect.profile

同樣,我可能已經得到了這一問題是錯誤的。

相關問題