我正在尝试使用QuerySet填充Django下拉列表。
形式
class PropertyForm(forms.Form):
prop1_names = Property.objects.values_list('prop1_name', flat = True).order_by('-prop_score')[:1]
prop2_names = Property.objects.values_list('prop2_name', flat = True).order_by('-prop_score')[:1]
props_queryset = prop1_names | prop2_names
properties = forms.ModelChoiceField(queryset = props_queryset)
两个' prop1_names'和' prop2_names'查询集基于相同的模型,并且prop1_name和prop2_name列都具有相同的数据类型。错误讯息:
File "/usr/local/lib64/python3.4/site-packages/django/db/models/query.py", line 1115, in _merge_sanity_check
% self.__class__.__name__
TypeError: Merging 'QuerySet' classes must involve the same values in each case.
感谢任何帮助。