Django ';ForwardManyToneDescriptor';对象没有属性';id';-错误

Django ';ForwardManyToneDescriptor';对象没有属性';id';-错误,django,object,view,attributes,iterable,Django,Object,View,Attributes,Iterable,我有一个模型: class TextBook(models.Model): code = models.CharField(max_length=200, unique=True) type = models.CharField(max_length=200) name = models.CharField(max_length=200) open_qty = models.DecimalField( max_digits = 4, decimal_places

我有一个模型:

class TextBook(models.Model):

    code = models.CharField(max_length=200, unique=True)
    type = models.CharField(max_length=200)
    name = models.CharField(max_length=200)
    open_qty = models.DecimalField( max_digits = 4, decimal_places = 0,default = 0)
    recived_qty =models.DecimalField( max_digits = 4, decimal_places = 0,default = 0)
    return_qty=models.DecimalField( max_digits = 4, decimal_places = 0,default = 0)
    issue_qty=models.DecimalField( max_digits = 4, decimal_places = 0,default = 0)
    bal_qty = models.DecimalField( max_digits = 4, decimal_places = 0,default = 0)
    avgcost =models.DecimalField( max_digits = 5, decimal_places = 2,default = 0.00)
    price =models.DecimalField( max_digits = 5, decimal_places =2,default = 0.00)
    class_name = models.ManyToManyField(SchClass, help_text='Select a class for this book')
    term = models.ManyToManyField(SchTerms, help_text='Select Terms')
    
    class TransBody(models.Model):
        trans_header = models.ForeignKey(TransHeader,on_delete=models.CASCADE,null=True)
        book = models.ForeignKey(TextBook,on_delete=models.CASCADE)
        quantity = models.IntegerField(default=0)
        price = models.FloatField(default=0)

    def get_absolute_url(self):
        """Returns the url to access a detail record for this book."""
        return reverse('select_stock_report', args=[str(self.id)])
我的看法是:

def listSelectStkTrans(request,id):
    # (note:return(HttpResponse(id) gives correct book id)
    allstktrans =TransBody.objects.filter(id=TransBody.book.id)
    context = {'allstktrans': allstktrans}
    return render(request, 'wstore/list_stk_trans.html', context)
我的网址:

 path('listselectstktrans/<int:id>/', views.listSelectStkTrans, name='select_stock_report'),
path('listselectstktrans/',views.listselectstktrans,name='select_stock_report'),
我的模板有以下链接:

{{book.code}}
我得到的“ForwardManyToneDescriptor”对象没有属性“id”-错误。

您不使用以下选项进行筛选:

allstktrans = TransBody.objects.filter(id=TransBody.book.id)
allstktrans = TransBody.objects.filter(book_id=id)