Using django-city-light with django-crispy-forms and django-ajax-selects

I need to have a form where the user enters a name, email and selects a city and country. I am using django-cities-light to populate the database with a list of cities and countries.

Then I create a form using django-crispy-forms using the database model as shown below.

Models.py

from cities_light.models import City, Country

class CustomModel(models.Model):
    name = models.CharField(max_length=500)
    email = models.EmailField(blank=True)
    city = models.ForeignKey(City)
    country = models.ForeignKey(Country)

      

Forms.py

Class EntryForm(forms.ModelForm):
    class Meta:
        model = CustomModel

    def __init__(self, *args, **kwargs):
        super(EntryForm, self).__init__(*args, **kwargs)

        self.helper = FormHelper(self)
        self.helper.layout.append(ButtonHolder(
            Submit('save', 'Save', css_class='btn-primary')
            )
        )

      

Using this in a view gives me a form with two text fields (for name, email) and two select fields (for city, country). Now, since the number of cities is quite large, I want to change them to textboxes, which use django-ajax-selects to display the names of cities or countries when the user starts typing.

The documentation section provides AJAX_LOOKUP_CHANNELS, but I can't figure out how to change my form and then hook it up with ajax-selects. Any help is appreciated.

+3


source to share


1 answer


See the documentation for django-ajax-selects for using django-ajax-selects: https://github.com/crucialfelix/django-ajax-selects#quick-installation



Note that @yourlabs we are now using django-autocomplete-light, so it is no longer supported, but it is available for users who have not yet migrated to django-autocomplete-light.

+3


source







All Articles