Skip to content

django-select2 whit django-cities loops. #41

Closed
@mikaelosterberg

Description

@mikaelosterberg

Hi

Can't get django-select2 play nice whit django-cities any one have a suggestion?

The problem is that on validation of a submitted from django-select2 loops the entier db off django-cities (22K+ rows) it takes a long time.

form.py

class CityClass(AutoModelSelect2Field):
    queryset=City.objects
    search_fields  = ['name__icontains', 'slug__icontains', 'name_std__icontains', ]

class UserForm(forms.Form):
    BIRTH_YEAR_CHOICES = range((date.today().year - 90), (date.today().year - 15))
    error_messages = {
        'duplicate_pagename': _("A page with that name already exists."),
        'duplicate_email':    _("A user with that email already exists."),
        'sixteen_or_older':    _("You have to be sixteen or older to join"),
    }
    email               = forms.EmailField(label=_('E-mail'),
                                        help_text = _("Required"))
    dob                 = forms.DateField(label=_('Date of birth'),                                       widget=extras.SelectDateWidget(years=BIRTH_YEAR_CHOICES),
                                        help_text = _("Required. Your date of birth"))
    city                = CityClass()

views.py

def newUser(request):
    if request.method == 'POST':
            form = UserForm(request.POST)
            if form.is_valid():
                messages.info(request,  form.cleaned_data)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions