Django int()参数必须是字符串、类似字节的对象或数字,而不是';方法';

Django int()参数必须是字符串、类似字节的对象或数字,而不是';方法';,django,django-models,django-views,Django,Django Models,Django Views,在django 1.8/python 3.4中 如何将方法转换为int 例如: models.py class Bid(models.Model): bid_Price = models.IntegerField(default=1) def __str__(self): return self.bid_Price def topPrice(self): return 100 view.py def BidView(request,

在django 1.8/python 3.4中

如何将方法转换为int

例如:

models.py

class Bid(models.Model):
    bid_Price = models.IntegerField(default=1)

    def __str__(self):
        return self.bid_Price

    def topPrice(self):
        return 100
view.py

def BidView(request, bid_id):
    bid_data = Bid.objects.get(id=bid_id)
    if int(bid_data.topPrice_text) < 100):
def BidView(请求、投标id):
bid\u data=bid.objects.get(id=bid\u id)
如果int(投标数据、价格文本)<100:

方法的编写方式已经返回了一个int,因此您需要实际调用该方法以使用其返回值:

if bid\u data.topPrice()<100:


我不得不说,我不太清楚你想在这里做什么,但无论如何,topPrice可能不应该是一种方法。

是的,这里有很多问题和不一致之处,但我指的是该方法(
bid_data.topPrice
),而不是调用它(
bid_data.topPrice()
)是导致给定异常的一个。