특정 항목에 대해 alternate_id를 검색했습니다. 이 검색은 공백없이 쉼표가있는 경우 여러 검색을 수행 할 수있는 대안을 허용 할 수 있습니다. 하지만 내 검색 양식에서 "부분 검색"을 수행 할 수 있기를 바랍니다. 그래서 *를 검색하면, 2ndid는 모든 결과를 줄 것입니다 ......, 2ndidDjango 검색 양식도 부분 검색을 할 수 있기를 원합니다.
대체 id는 문자열입니다. 정수가 아닙니다. 내가 복수 검색을 수행 할 수 있었기 때문에 __in
이라는 유일한 이유가있었습니다.
def search_item(request, client_id = 0):
client = None
if client_id != 0:
try:
client = models.Client.objects.get(pk = client_id)
except:
pass
items = None
Q_alt_ids = Q()
if request.method == 'POST':
form = forms.SearchItemForm(request.POST)
if form.is_valid():
alternate_id = form.cleaned_data['alternate_id']
items = client.storageitem_set.all()
if alternate_id:
alternate_ids= alternate_id.lower().split(",")
Q_alt_ids = Q(alternative_id__in = alternate_ids)
return render_to_response('items.html', {'items':items, 'client':client}, context_instance = RequestContext(request))
else:
HttpResponse(client)
if client is not None:
form = forms.SearchItemForm(initial = {'client':client.pk})
else:
form = forms.SearchItemForm()
return render_to_response('search_items.html', {'form':form}, context_instance = RequestContext(request))
제 의견을 편집하도록 도와주십시오. 파일을 편집하기가 어렵습니다. – Shehzad009
기록을 위해 이것은 이메일을 통해 해결되었습니다. 나는 너를 무시한 것처럼 보이기를 원하지 않는다. :피 –