I have the following table models.
class Experience(models.Model):
name = models.CharField(max_length=50)
created = models.DateTimeField(auto_now_add=True)
updated = models.DateTimeField(auto_now=True)
about = models.TextField()
def __unicode__(self):
return self.name
class Level(models.Model):
level = models.IntegerField()
details = models.TextField()
created = models.DateTimeField(auto_now_add=True)
updated = models.DateTimeField(auto_now=True)
started = models.IntegerField(default=0)
completed = models.IntegerField(default=0)
exp = models.ManyToManyField(Experience, through='ExperienceLinks')
def __unicode__(self):
return "Level %i" % self.level
class ExperienceLinks(models.Model):
experience = models.ForeignKey(Experience, on_delete=models.CASCADE)
level = models.ForeignKey(Level, on_delete=models.CASCADE)
created = models.DateTimeField(auto_now_add=True)
updated = models.DateTimeField(auto_now=True)
modifier = models.IntegerField(default=1)
Passing in a level object to the template I'm trying to get the modifier for the experience for the level. I'm trying
{% for exp in level.exp.all %}
<p><span class="label label-secondary ">{{ exp }} (+{{ exp.modifier }})</span></p>
{% endfor %}
I'm only getting the following for an output
exp1 (+)
exp2 (+)
So I can't access the modifier how i'd like to.
Thanks for the help