0

在 Django 中,我过滤了数据并显示了类似的结果。例如

Alabama(20)
Iowa(12)

这里“阿拉巴马州,爱荷华州”是州名,括号内的“20,12”是否。特定州提供的工作机会。单击阿拉巴马州或爱荷华州时,它会显示该特定州的职位空缺。但我没有将 emp_id 传递给模板页面。给这个想法...

模型.py

class User(models.Model):
     first_name= forms.CharField(max_length=30,widget=forms.TextInput())
     last_name = forms.CharField(max_length=30,widget=forms.TextInput())
     username = forms.CharField(max_length=30,widget=forms.TextInput())
     email = forms.EmailField(widget=forms.TextInput())
     password = forms.CharField(widget=forms.PasswordInput())
     companyname = forms.CharField(max_length=30,widget=forms.TextInput())

class jobs(models.Model):
     emp = models.ForeignKey(User, unique=False)
     title = models.CharField(max_length=30)
     referencecode = models.CharField(max_length=30)
     jobsummary = models.TextField()
     jobdetails = models.TextField()
     key_skills = models.CharField(max_length=30)
     states = models.CharField(max_length=30)

视图.py

def search_result(request):
     details3 = jobs.objects.values('state').annotate(count=Count('state')).order_by('-count')
     return render_to_response('searchresult.html', {'details3': details3})

搜索结果.html

{% for d2 in details3 %}
<li><a style="text-decoration:none;" href="/accounts/CompanyList/{{d2.emp}}/" >{{ d2.state}}({{ d2.count }})</a></li>
{% endfor %}
4

1 回答 1

0
jobs.objects.values('state')

您只选择state字段,为什么您还期望emp在那里?

jobs.objects.values('state', 'emp_id')

这是你想要的吗?

于 2013-04-25T04:55:14.140 回答