I have a Django app where my main Model has ForeignKey fields to other DB tables.
class Bugs(models.Model):
bug_id = models.PositiveIntegerField(primary_key=True)
bug_severity = models.ForeignKey(Bug_severity,null=True)
priority = models.ForeignKey(Priority,null=True)
bug_status = models.ForeignKey(Bug_Status,null=True)
resolution = models.ForeignKey(Resolution,null=True)
etc...
All of the ForeignKey tables have a unicode function that returns the name that I want displayed in the template.
class Priority(models.Model):
value = models.CharField(max_length=64)
sortkey = models.PositiveSmallIntegerField()
isactive = models.NullBooleanField()
visibility_value_id = models.SmallIntegerField(null=True,blank=True)
def __unicode__(self):
return self.value
In the view, I am running the query as:
bugs = Bugs.objects.filter(active=True).order_by('priority__sortkey','bug_severity__sortke
In the template, I can iterate through them, and display the ForeignKey value correctly.
{% for bug in bugs %}
<tr class="bugrow" >
<td>{{bug.bug_id}}</td>
<td>{{bug.priority}}</td>
<td>{{bug.bug_severity}}</td>
<td>{{bug.bug_status}}</td>
<td>{{bug.resolution}}</td>
The problem I am having is that I need to manipulate the Bugs data before sending it to the template, so I use the values() method to return a dictionary. When I pass that dictionary to the template it does not show any fields that point to a ForeignKey.
I'm pretty sure that the reason is that the values only returns the actual database value, so it cannot follow the FK.
The question is, how can I manipulate the data sending it to the template, and still follow the ForeignKey?