在模型类定义语句里面,加上一句:
objects = models.Manager()
例如:
class BidRecord(models.Model):
"""
出价(竞价)记录表
"""
status_choice = {
(1, '竞价'),
(2, '成交'),
(3, '逾期未付款'),
}
status = models.PositiveSmallIntegerField(verbose_name='状态', choices=status_choice, default=1)
item = models.ForeignKey(verbose_name='拍品', to='AuctionItem', on_delete=models.CASCADE)
user = models.ForeignKey(verbose_name='出价人', to='UserInfo', on_delete=models.CASCADE)
price = models.PositiveIntegerField(verbose_name='出价')
objects = models.Manager()
查询的时候就有提示了:
models.BidRecord.objects.filter(item_id=item_id,price=price)