在 Django 中,我需要过滤数据并显示结果。例如
Alabama(20)
Iowa(12)
这里“阿拉巴马州,爱荷华州”是州名,括号内的“20,12”是否。特定州提供的工作机会。
模型.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)
我试图给views.py就像
def search_result(request):
details = jobs.objects.annotate().order_by('state')
return render_to_response('searchresult.html', {'details': details})
templates
<ul>
{% for d1 in details %}
<li>{{ d1.state }}({{ d1.count }})</li>
{% endfor %}
</ul>
它只显示州名而不是计数。澄清一下。