基于外键加入Django

时间:2014-06-21 22:14:02

标签: python django

我的模特就像这样

class News(models.Model):
    idnews = models.IntegerField(primary_key=True)
    source = models.TextField(blank=True)
    title = models.TextField(blank=True)


class NounPlural(models.Model):
    idnoun_plural = models.IntegerField(db_column='idNoun_Plural', primary_key=True) # Field name made lowercase.
    nns = models.TextField(db_column='NNS', blank=True) # Field name made lowercase.
    news_idnews = models.ForeignKey(News, db_column='news_idnews')

我的观点是这样的

 from projapp.models import News
 from projapp.models import NounPlural
     result = NounPlural.objects.select_related()

当我这样做时NounPlural.objects.select_related()我只获得NounPlural字段而不是News字段。我在Queryset中想要的是拥有NounPlural的所有字段和News的title字段。 如何实现这一目标?

0 个答案:

没有答案