【发布时间】:2013-10-10 01:36:13
【问题描述】:
试图了解如何在 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})
test.html
{{ o.test }}
我的页面是空白的,但它应该显示“测试”。我做错了什么?
【问题讨论】:
标签: python django django-models django-views django-custom-manager