0
我在我的一個類中有一個addedBy
的字段。我已經建立了一個計數這一領域如下:用戶名不能正確顯示
user_count = Issues.objects.values('addedBy').annotate(count=Count('id'))
然後在我的模板,我訪問變量
{% if user_count %}
<div class="menutitle"><strong>{% trans "Added By" %}</strong></div>
{% for item in user_count %}
<ul>
<li><a href="#">{{ item.addedBy }} ({{ item.count }})</a> </li>
</ul>
{% endfor %}
{% endif %}
但我得到的是用戶的ID不用戶名。
編輯:Issues
型號
class Issues(models.Model):
ISSUE_CHOICES = (
('Mechanical', 'Mechanical'),
('Dent', 'Dent'),
('Interior', 'Interior'),
('Body', 'Body'),
('Part', 'Part'),
('Other', 'Other'),
)
ISSUE_STATUS_CHOICES = (
('In Progress', 'In Progress'),
('Completed', 'Completed'),
('Pending', 'Pending'),
)
vehicle = models.ForeignKey(Vehicle)
description = models.CharField('Issue Description', max_length=30,)
type = models.CharField(max_length=10, default='Other', choices=ISSUE_CHOICES)
status = models.CharField(max_length=12, default='Pending',
choices=ISSUE_STATUS_CHOICES)
priority = models.IntegerField(default='8', editable=False)
addedBy = models.ForeignKey(User, related_name='added_by', editable=False)
assignedTo = models.ForeignKey(User, related_name='assigned_by', blank=True,
null=True)
dateTimeAdded = models.DateTimeField('Added On', default=datetime.today,
editable=False)
last_updated = models.DateTimeField(default=datetime.today,
editable=False)
def __unicode__(self):
return self.description
def save(self):
self.last_updated = datetime.now()
super(Issues, self).save()
你究竟在哪裏期待用戶名來自哪裏? – 2010-03-04 13:35:25
向我們展示'models.py'中'Problems'模型的定義。 – 2010-03-04 14:09:27