17
我正在努力爲我的項目獲得正確的查詢。 下面是一個例子或我的模型:Django篩選器查詢外鍵
from django.db import models
class Publisher(models.Model):
name = models.CharField(max_length=30)
address = models.CharField(max_length=50)
city = models.CharField(max_length=60)
state_province = models.CharField(max_length=30)
country = models.CharField(max_length=50)
website = models.URLField()
def __unicode__(self):
return self.name
class Author(models.Model):
first_name = models.CharField(max_length=30)
last_name = models.CharField(max_length=40)
email = models.EmailField()
def __unicode__(self):
return u'%s %s' % (self.first_name, self.last_name)
class Book(models.Model):
title = models.CharField(max_length=100)
authors = models.ManyToManyField(Author)
publisher = models.ForeignKey(Publisher)
publication_date = models.DateField()
def __unicode__(self):
return self.title
我怎麼出版商從書類的例子,我想所有的出版商有標題以「你好」所有的書? 謝謝
它的工作^^多謝你救了我的最後期限^^ – 2013-03-19 18:19:27
如果我想看到一些出版商出版的所有書籍? – 2016-11-10 13:45:47
@ArindamRoychowdhury:'Book.objects.filter(publisher__name ='Some')' – 2016-11-10 19:31:42