Свет автозаполнения Django: нет поля ввода

Я установил "Django autocomplete light" и теперь следую этому руководству: http://django-autocomplete-light.readthedocs.io/en/master/tutorial.html

Вот мой код:

настройка.py

INSTALLED_APPS = [
    'dal',
    'dal_select2',
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.gis',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'accounts',
    'directory',
    'geopy',
]

модели.py

class Company(models.Model):
    CATEGORY_CHOICES = (
        ('P', 'Parrucchiere'),
        ('Ce', 'Centro estetico'),
    )
    self_key = models.ForeignKey('self', null=True, blank=True, related_name='related_self_key_models')
    city = models.ForeignKey(City, on_delete=models.CASCADE)
    name = models.CharField(max_length=200)
    address = models.CharField(max_length=255)
    telephone = models.CharField(max_length=200)
    category = models.CharField(max_length=1, choices=CATEGORY_CHOICES, null=True)
    email = models.CharField(max_length=255, null=True, blank=True)
    vat = models.CharField(max_length=200, null=True, blank=True)
    location = gis_models.PointField(u"longitude/latitude", geography=True, blank=True, null=True)
    gis = gis_models.GeoManager()
    objects = models.Manager()
    slug = AutoSlugField(populate_from='name', null=True)
    def __str__(self):
        return self.name

просмотры.py

class CompanyAutocomplete(autocomplete.Select2QuerySetView):
    def get_queryset(self):
        # Don't forget to filter out results depending on the visitor !
        if not self.request.user.is_authenticated():
            return Company.objects.none()

        qs = Company.objects.all()

        if self.q:
            qs = qs.filter(name__istartswith=self.q)

        return qs

формы.py

class AddCompanyForm(forms.ModelForm):
    vat = forms.CharField(required=True)
    class Meta:
        model = Company
        fields = ('name','city','address','telephone','email','vat','self_key')
        widgets = {
            'self_key': autocomplete.ModelSelect2(url='company-autocomplete')
        }
    def clean_vat(self):
        vat = self.cleaned_data['vat']
        if Company.objects.filter(vat__iexact=vat).count() > 1:
            raise ValidationError("L'attività digitata esiste già...")
        return vat

urls.py

url(
    r'^company-autocomplete/$',
    autocomplete.Select2QuerySetView.as_view(model=Company),
    name='company-autocomplete'
),

HTML

{% extends 'base.html' %}
{% load static %}

{% block title %}
  <title>Aggiungi azienda | ebrand directory</title>
{% endblock title %}

{% block upper_content %}
<br style="line-height:25px"/>
<div class="google-card-full" style="width:auto; height:auto; text-align:center;">
  <br style="line-height:25px"/>
  <h1 class='title'><img style="width:auto; height:auto;" src='{% static "images/new_company.png" %}'> Aggiungi azienda</h1>
  <hr/>
  <br/>
  <form method="post">
    {% csrf_token %}
    <table class='form-group' style="width:25%; margin:auto;">
      {% for field in form.visible_fields %}
        <tr>
          <th style='text-align:left'>{{ field.label|capfirst }}:</th>
          {% if forloop.first %}
            {% for hidden in form.hidden_fields %}
              {{ hidden }}
            {% endfor %}
          {% endif %}
          {{ field.errors.as_ul }}
          <td style='text-align:right'>{{ field }}</td>
        </tr>
      {% endfor %}
    </table>
    <br/>
    <button class="btn btn-raised btn-primary" type="submit"
            style="background-color:#1A88B9;">Aggiungi</button>
  </form>
  <p style="height:5px"/>
  <p><b>ATTENZIONE</b>: ebrand<sup>©</sup> si riserva di verificare l'autenticità dei dati<br/>
     prima dell'inserimento dell'azienda all'interno del database.</p>
  <p style="height:5px"/>
</div>
<h2 style='margin:0px 0px 15px 25px;'>Oppure...</h2>
<div class="google-card-full" style="width:auto; height:auto; text-align:center;">
  <br style="line-height:25px"/>
  <h1 class='title'><img style="width:auto; height:auto;" src='{% static "images/new_company.png" %}'> Reclama azienda esistente</h1>
  <hr/>
  <br/>
  <form method="post">
    {% csrf_token %}
    <table class='form-group' style="width:25%; margin:auto;">
      {% for field in form.visible_fields %}
        <tr>
          <th style='text-align:left'>{{ field.label|capfirst }}:</th>
          {% if forloop.first %}
            {% for hidden in form.hidden_fields %}
              {{ hidden }}
            {% endfor %}
          {% endif %}
          {{ field.errors.as_ul }}
          <td style='text-align:right'>{{ field }}</td>
        </tr>
      {% endfor %}
    </table>
    <br/>
    <button class="btn btn-raised btn-primary" type="submit"
            style="background-color:#1A88B9;">Aggiungi</button>
  </form>
  <p style="height:5px"/>
</div>
{% endblock %}

{% block middle_content %} {% endblock %}
{% block content %} {% endblock %}
{% block bottom_content %} {% endblock %}

Проблема: поле 'self_key' не заполнено, а также я не могу ввести (это не ввод).

Я уже рассматривал этот вопрос безрезультатно: Django autocomplete light: поле не заполнено


person Alessio Ferri    schedule 31.10.2017    source источник
comment
вы можете сделать это без autocomplete-pkg, прочитав это   -  person mohammedgqudah    schedule 31.10.2017
comment
@mohammedqudah Вы, сэр, спасли мой день!   -  person Alessio Ferri    schedule 31.10.2017
comment
это сработало? с тобой   -  person mohammedgqudah    schedule 31.10.2017
comment
@mohammedqudah да, это сработало отлично!   -  person Alessio Ferri    schedule 31.10.2017