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 should link it to the Country that already exists, so i want to use 'autocomplete field' in my template to get Country from DB
I have the following form defined:
class AddCityForm(forms.ModelForm):
city_name = forms.CharField(max_length=100)
country_name = forms.CharField(max_length=100)
In my template i have the forms like this :
<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 field 'country_name' autocompleted from the databese ?
cheers, newbie in django.
As time passes, Django applications rise and fall. There's a grid on djangopackages.org
that compares various autocompletion solutions and provides hints on their development status: https://djangopackages.org/grids/g/auto-complete/
Yes. You can check django-autocomplete out
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With