2

大文字と小文字を区別する正確な一致を使用する代わりに、包含フィルターで大文字と小文字を区別しない検索を実行する必要があります。

def filter(request, fname, fvalue):

    list = HmsPatient.objects.filter(**{fname:fvalue})
    c = {'list' : list}
    return render_to_response('patient/list.html', c, context_instance=RequestContext(request))

def search(request):
    if request.method == 'POST':
        fname = request.POST.get('filter_name')
    fvalue = request.POST.get('filter_value')
        return filter(request, fname, fvalue);
    else:
        action = HmsPatient().get_search_url()
        form = HmsPatientForm()
        c = {'form': form, 'action' : action}
        c.update(csrf(request))
        return render_to_response('search.html', c, context_instance=RequestContext(request))
4

2 に答える 2

2

大文字と小文字を区別しない検索には、二重引用符 n "icontains" を使用します。

def filter(request, fname, fvalue):

    key = fname + '__icontains'
    list = HmsPatient.objects.filter(**{key: fvalue})
    c = {'list' : list}
    return render_to_response('patient/list.html', c, context_instance=RequestContext(request))

大文字と小文字を区別する検索には、二重引用符 n "contains" を使用します。

def filter(request, fname, fvalue):
    key = fname + '__contains'
    list = HmsPatient.objects.filter(**{key: fvalue})
    c = {'list' : list}
    return render_to_response('patient/list.html', c, context_instance=RequestContext(request))

MySQL では、照合を選択すると、データ値の大文字と小文字が区別されます。照合を選択しない場合、データベースは大文字と小文字を区別しません。つまり、Abc = abc です。

于 2012-10-08T08:24:10.150 に答える
2

Django では、 を使用して大文字と小文字を区別しない一致を行うことができますiexact。例えば:

Blog.objects.get(name__iexact="beatles blog")

あなたの場合、fname変数であるため__iexact、辞書のキーに追加する必要があります。

key = fname + '__iexact'
list = HmsPatient.objects.filter(**{key: fvalue})

Django は と もサポートしてcontainsおりicontains、同じように使用できます。

于 2012-10-04T11:55:42.493 に答える