0

I have Event objects being shown properly. But I can't seem to grab the result from a python function and place it into the template.

For instance, this is my Event model.

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)

I can successfully pull everything into my template except attendees... For instance within a search context, I'm passing events as results...

{{ result.name }} is passed into my template fine, so is {{ result.location }}.

But {{ result.attendees|length }} won't show.

Any idea why this is? Help would be greatly appreciated.

1 Answer 1

2

You need to use {{ result.attendees }} (no |length).

The length filter works on lists and other iterables. What you're doing there is similar to applying len(len(something)), which is obviously wrong.

Sign up to request clarification or add additional context in comments.

1 Comment

It seems that {{ result.attendees }} doesn't show either. :/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.