2012-10-15 5 views
0

제대로 표시되는 이벤트 객체가 있습니다. 하지만 파이썬 함수에서 결과를 가져 와서 템플릿에 배치 할 수 없습니다.python 함수에서 템플릿으로 정보를 가져 오는 중 사용

예를 들어, 이것이 내 이벤트 모델입니다.

class Event(models.Model): 
    created = models.DateTimeField(auto_now_add=True) 
    modified = models.DateTimeField(auto_now=True) 
    name = models.CharField(max_length=200) 
    location = models.CharField(max_length=200) 
    students = models.ManyToManyField(StudentProfile, null=True, blank=True) 
    managers = models.ManyToManyField(ManagerProfile, null=True, blank=True) 

    def __unicode__(self): 
     return self.name 

    def attendees(self): 
     return len(self.students.count + self.managers.count) 

{{ result.name }}

내 템플릿 벌금에 전달

나는 성공적으로 내가 결과로 이벤트를 전달하고있어, 검색 컨텍스트 내에서 예를 들어 ... 참석자를 제외하고 내 템플릿에 모든 것을 해낼 수 ... , 그래서 {{ result.location }}입니다.

그러나 {{ result.attendees|length }}은 표시되지 않습니다.

이유가 무엇인가요? 도움말 크게 감사하겠습니다.

답변

2

{{ result.attendees }} (아니 |length)을 사용해야합니다.

length 필터는 목록 및 기타 iterables에서 작동합니다. 당신이하는 일은 명백히 틀린 len(len(something))을 적용하는 것과 비슷합니다.

+0

'{{result.attendees}} '도 표시되지 않는 것 같습니다. : / – Modelesq

관련 문제