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
- [Answered ]-FieldError: Unknown field(s) (created_at, modified_at) specified for Account
- [Answered ]-How to use checkboxes in Django Admin for a ManyToMany field through a model
- [Answered ]-Special characters in filenames and paths
- [Answered ]-Python xhtml2pdf table cell text display to vertical
Source:stackexchange.com