我尝试使用具有特定类别的类Book过滤作者,但我无法获得确切的类别。
models.py
class Book(models.Model):
category = models.CharField()
foreignkey = models.ForeignKey(Author, related_name="auth")
class Author(models.Model):
author_id = models.IntegerField(primary_key=True)
views.py
book = models.Book.objects.filter(category = 'Space')
author = models.Author.objects.filter(author_id__in = book )
答案 0 :(得分:0)
class Book(models.Model):
category = models.CharField()
author = models.ForeignKey(Author, related_name='books')
class Author(models.Model):
# pks are added automatically
在views.py
中books = models.Book.objects.filter(category='Space')
authors = models.Author.objects.filter(pk__in=[b.author_id for b in books])
答案 1 :(得分:0)
/feeds/feed.xml