2017-06-23 77 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

同样,我可能已经得到了这一问题是错误的。

相关问题