我嘗試篩選具有特定類別的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)
'book = models.Book.objects.filter(category ='Space')'但是您的Book類中的類別是'models.IntegerField()'。可以過濾'category ='或將類別更改爲'models.CharField()'。另外,你用你的作者過濾器試着做什麼? –
Bott0610
對不起,我舉了一個錯誤的例子。 – max