Autocomplete Field in Django

I have models similar to the following:

class Country(models.Model): name = models.CharField(max_length=50, unique=True) class City(models.Model): name = models.CharField(max_length=50, unique=True) country = models.ForeignKey(Country) 

and essentially I want to add a city to the database in my template. Before that, I have to link it to an existing country, so I want to use the "autocomplete field" in my template to get the country from the database

I have the following form:

 class AddCityForm(forms.ModelForm): city_name = forms.CharField(max_length=100) country_name = forms.CharField(max_length=100) 

In my template, I have the following forms:

 <form action="/city/add" method="post">{% csrf_token %} {{ add_city_form.as_p }} <input type="submit" value="Submit" /> </form> 

so is there any solution in django to make the 'country_name' field autocomplete from databese?

amuses, new to django.

+6
source share
2 answers

Yes. You can check django-autocomplete outside

+2
source

Over time, Django applications grow and decline. There is a grid on djangopackages.org that compares various autocomplete solutions and gives tips on their development status: https://djangopackages.org/grids/g/auto-complete/

0
source

All Articles