试图了解如何在 Django 中制作自定义函数。我有以下内容:
楷模:
class OptionManager(models.Manager):
def test(self):
test = "test"
return test
class Option(models.Model):
value = models.CharField(max_length=200)
objects = OptionManager()
def __str__(self):
return self.value
看法:
def questn(request, question_id):
o = Option.objects.filter(question=question_id).annotate(num_votes=Count('answer'))
return render(request, 'test.html', {'o':o})
测试.html
{{ o.test }}
我的页面是空白的,但它应该显示“测试”。我究竟做错了什么?