Django Поиск полей

У меня проблемы с использованием objects.filter в Django Field lookup. У меня есть модель Django, как показано ниже в моем models.py:

class operationOPCSmatcher(models.Model):
    operationID = models.IntegerField(primary_key = True)
    operationName = models.CharField(max_length=255, blank=True, null=True)
    opcsName = models.CharField(max_length=255, blank=True, null=True)
    opcsCode = models.CharField(max_length=20, blank=True, null=True)

    class Meta:
        ordering = ['-operationID']

Я использую поиск на уровне полей в моей таблице, используя код ниже в моем views.py файле:

   from .models import operationOPCSmatcher

   def opnotenerOutput(request):
        context = {}
        opnote = request.POST.get("opnote")
        doc = nlp(opnote)
        context['doc'] = doc

        #find matching OPCS codes
        opcsNames = {}
        for ent in doc.ents:
            if  ent.label_ == "OPERATION":
                opcsNames = operationOPCSmatcher.objects.filter(operationName__contains=ent.text).values()

        context['opcsNames'] = opcsNames

    return render(request, "opnotener-output1.html", context)

Я пытаюсь найти совпадающие записи с "operationName" LIKE ent.text

SQL: WHERE operationName LIKE ent.text)

У меня в файле шаблона opnotener-output1.html следующий код:

<h2>Operation(s)</h2>
<ol>
{% for ent in doc.ents %}
    {% if ent.label_ == "OPERATION" %}
    <li>
    <!-- create table-->
    <table border='1'>
        <tr>
            <th>{{ ent.text }}</th>
            <th>OPCS Name</th>
            <th>OPCS Code</th>
        </tr>
        {% for x in opcsNames %}
            {% if x.OperationName == ent.text %}
            <tr>
                <th></th>
                <th>{{ x.OpcsName }}</th>
                <th>{{ x.OpcsCode }}</th>
            </tr>
            {% else %}
            <tr>
                <th></th>
                <th>No OPCS codes</th>
                <th>No OPCS coses</th>
            </tr>
            {% endif %}
        {% endfor %}
    </table>
    <!-- end opcs table -->
    </li>
    {% endif %}
{% endfor %}
</ol>

Spacy nlp часть кода, кажется, работает хорошо, но поиск на уровне поля таблицы, кажется, не работает (хотя в таблице есть совпадающие записи). Может ли кто-нибудь помочь отладить этот код? Большое спасибо!

Вернуться на верх