[Answered ]-Calling Model function in template not working

1👍

This has nothing to do with calling it from the template.

self.skill is already an instance of Skill. There is no need to query that model explicitly.

def skillcategory(self):
    return self.skill.skillset_choice    

And in fact this method is pretty pointless; you certainly can do it directly in the template:

skillsetchoice {{ item.skill.skillset_choice }}

1👍

Replace self.skill with self.skill.id (in older versions of Django your code would work by the way):

def skillcategory(self):
    return Skill.objects.get(id = self.skill.id).skillset_choice

But this is much better:

def skillcategory(self):
    return self.skill.skillset_choice

But do you really need this method? You can use:

{{ item.skill.skillset_choice }}

If you want to display cat1, then (get_foo_display):

{{ item.skill.get_skillset_choice_display }}
👤avd

Leave a comment