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.
source share