使用DjangAutoCompleteLight自动完成

2024-05-29 07:38:34 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在Django开发一个项目,我希望在我的搜索中使用autocompletement,但是我丢失了Django-autocomplete-light’s 的代码 但没用。在

首先我安装了它:

pip install django-autocomplete-light

在我放入已安装的应用程序和网址后:

^{pr2}$

但是我在这里失去了我。在

这是我的模型:

class Tecnico(models.Model):
    codigo = models.AutoField(primary_key=True)
    nome = models.CharField(max_length=60)
    endereco = models.CharField(max_length=60, blank=True, null=True)
    numero = models.CharField(max_length=10, blank=True, null=True)
    bairro = models.CharField(max_length=40, blank=True, null=True)
    cidade = models.IntegerField(blank=True, null=True)
    fone = models.CharField(max_length=14, blank=True, null=True)
    cpf = models.CharField(max_length=18, blank=True, null=True)
    sexo = models.CharField(max_length=1, blank=True, null=True)
    data_nasc = models.DateField(blank=True, null=True)
    data_inc = models.DateField(auto_now_add=True, blank=True, null=True)
    status = models.CharField(max_length=1, blank=True, null=True)

   class Meta:
        db_table = 'tecnico'

这是我的HTML代码:

<div class="container">
    <form action="">
        <div class="col">
            <div class="col-1-2 first">
                <label class="label" for="nome">Nome</label>
                <input class="input varchar autocomplete" type="text" autofocus>
                <ul class="list-autocomplete">
                     {# Show my list here #}
                </ul>
            </div>
            <div class="col-1-2">
                <input class="button no-label" id="action-button" type="button" value="Pesquisar">
            </div>
        </div>
    </form>
</div>
<div class="col">
    <table class="container--fluid table">
        <thead>
            <tr>
                <th>Código</th>
                <th>Nome</th>
                <th>Telefone</th>
                <th>CPF</th>
                <th>Data de nasc.</th>
            </tr>
        </thead>
        {% for Tecnico in tecnicos %}
        <tbody>
            <tr>
                <td class="align-center">{{Tecnico.codigo}}</td>
                <td>{{Tecnico.nome}}</td>
                <td class="align-center">{{Tecnico.fone}}</td>
                <td class="align-center">{{Tecnico.cpf}}</td>
                <td class="align-center">{{Tecnico.data_nasc}}</td>
            </tr>
        </tbody>
        {% empty %}
            <div>
                Nenhum resultado foi encontrado
            </div>
        {% endfor %}
    </table>
</div>
<div class="col">
    <div class="float-right align-right no-margin-bottom">
        <a class="input button gradient-green" href="/tecnicos-incluir/">Incluir novo</a>
    </div>
</div>

我想在我的HTML中显示列表。在

很抱歉扩展代码。在

我把自动完成灯工作在我的搜索?在


Tags: divtruemodelscolautocompletenulllengthmax

热门问题