django-autocomplete-light - how to return a different field then a models primary key?
<p>I am using django-autocomplete-light</p>

<p>in a form for a model I want to use autocomplete on one of its field. the field is not a foreignkey or something, but just a integer field and for autocomplete I would actually like to use the same model then the form I am filling. </p>

<p>The query set from autocomplete however returns the ID and I want to fill the field "projektnummer".</p>

<p>Any clue how I can setup autocomplete so that it returns not the primary key of the model but some other field?</p>

<p>also it seems that I get a wired failure from crispy forms when I use the autocomplete-widget on the integer field.</p>

<p>models.py</p>

<pre><code>class KombiPublikation(models.Model):
    typid = models.ForeignKey('KombiPublikationsTypMedium', verbose_name='Outputtyp', db_column='typid') # publikationstyp.id or publikationstypinfo.typid
    [...]
    projektnummer = models.IntegerField(verbose_name='Projektnr.', default=0, blank=True)
[...]
</code></pre>

<p>views.py</p>

<pre><code>class SearchProjectinFormAutocomplete(autocomplete.Select2QuerySetView):
    def get_queryset(self):
        qs = KombiPublikation.objects.filter(typid__in=[222, 223, 224]).filter(zeigen=1)

        if self.q:
            qs = qs.filter(Q(projektnummer__contains=self.q))

        return qs
</code></pre>

<p>forms.py</p>

<pre><code>class KombiPublikationForm(forms.ModelForm):

    class Meta:
        model = KombiPublikation
        #fields = []
        exclude = ['pub_sprache']
        widgets = {
            'typid': autocomplete.ModelSelect2(url='output:typ-autocomplete', forward=['typtyp']),
            'projektnummer': autocomplete.ModelSelect2(url='output:projekt-form-autocomplete'),
        }
</code></pre>