python - Calling Model function in template not working -
i'm trying category of skill in template. post read, can't directly information foreign key in template. instead, add function on characterskill models skill category
models.py
class character(models.model): name = models.charfield(max_length=70) class skill(models.model): name = models.charfield(max_length=70) cat1 = '01' skillset_choice = ((cat1:'cat1')) skillset_choice = models.charfield( max_length=2, choices = skillset_choice, default='', blank=true, null=true, ) class characterskill(models.model): character = models.foreignkey(character, on_delete=models.cascade) skill = models.foreignkey(skill, on_delete=models.cascade) def skillcategory(self): return skill.objects.get(id = self.skill).skillset_choice
template
skillsetchoice {{item.skillcategory}}
but error :
exception type: typeerror exception value: int() argument must string or number, not 'skill'
i tried inpect value shell console can category id when use in template, nothing working
hope can me!
this has nothing calling template.
self.skill
already instance of skill. there no need query model explicitly.
def skillcategory(self): return self.skill.skillset_choice
and in fact method pretty pointless; can directly in template:
skillsetchoice {{ item.skill.skillset_choice }}
Comments
Post a Comment