使用django-autocomplete-light自动完成

时间:2022-03-18 01:40:24

I'm developing a project in Django, and I would like autocomplemente in my search, but I've lost on the code of Django-autocomplete-light’s and it'd not worked.

我正在Django开发一个项目,我想在我的搜索中自动完成,但是我已经迷失了Django-autocomplete-light的代码并且它没有用。

First I installed it:

首先我安装它:

pip install django-autocomplete-light

After I put in INSTALLED_APPS and url:

在我输入INSTALLED_APPS和url之后:

INSTALLED_APPS = (
    #...
    'django.contrib.staticfiles',
    'autocomplete_light'
)

# URLS
url(r'^autocomplete/', include('autocomplete_light.urls')),

However I've lost me here.

但是我在这里失去了我。

This is my model:

这是我的模特:

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'

And this is my HTML code:

这是我的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>

I want show list in my HTML.

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

Sorry for extend code.

对不起扩展代码。

Where I put autocomplete light for work in my search?

在我的搜索中我将自动完成灯用于工作的位置?

1 个解决方案

#1


0  

This is the documentation to create a navigation autocomplete: http://django-autocomplete-light.readthedocs.io/en/2.3.0/navigation.html

这是创建导航自动完成的文档:http://django-autocomplete-light.readthedocs.io/en/2.3.0/navigation.html

It's used in the search form of this website: http://societecitoyenne.org/

它在本网站的搜索表单中使用:http://societecitoyenne.org/

#1


0  

This is the documentation to create a navigation autocomplete: http://django-autocomplete-light.readthedocs.io/en/2.3.0/navigation.html

这是创建导航自动完成的文档:http://django-autocomplete-light.readthedocs.io/en/2.3.0/navigation.html

It's used in the search form of this website: http://societecitoyenne.org/

它在本网站的搜索表单中使用:http://societecitoyenne.org/