擅长:python、mysql、java
<p>尽管前面的答案看起来是正确的,但是在服务器端有一个更简单的方法来处理这个问题。在</p>
<p><code>values_list</code>有一个<code>flat</code>参数来返回一个平面列表而不是列表列表(<a href="https://docs.djangoproject.com/fr/1.8/ref/models/querysets/#values-list" rel="nofollow">https://docs.djangoproject.com/fr/1.8/ref/models/querysets/#values-list</a>)</p>
<p>因此,你的观点应该是:</p>
<p>类资源视图(JSONResponseMixin,View):</p>
<pre><code>def get(self, request, *args, **kwargs):
status = 'error'
msg = "Success"
# Getting the x value from url/queryset
fab = self.request.GET.get('x')
mas = self.request.GET.get('mas')
# DRCForecast Masksets
queryset_df = Forecast.objects.filter(Q(x=int(fab)) | Q(x=int("0"+x)))\
.values_list('mas', flat=True).distinct()
# OrcRecord Masksets
queryset_or = Record.objects.filter(Q(pc_ext__x=int(x)) | Q(pc_ext__x=int("0"+x)))\
.values_list('mas', flat=True).distinct()
new_mas_list = list(set(list(queryset_df) + list(queryset_or)))
new_mas_list.sort()
return self.render_json_response(dict(objects=new_mas_list))
</code></pre>