[Answered ]-Applying conditional in Django CharFields interaction

1👍

For the ‘User Experience’, i think you will need to write a javascript to change all distance according the clustering_method_param selected.

But, if you just want to ‘block’ this on django.
You can write a form validation, like this:

def clean(self):
    cleaned_data = self.cleaned_data
    clustering_method_param = cleaned_data.get('clustering_method_param', None)
    distance_method_param = cleaned_data.get('distance_method_param', None)

    if clustering_method_param == 'ward':
        if distance_method_param != 'euclidean':
            self.errors.update(
                {
                    'distance_method_param': [u'It should be euclidean.']
                }
            )
    return cleaned_data

1👍

Using JavaScript and Ajax is a proven fix for your problem. You can listen to the user selection on first drop-down and then display the second drop-down accordingly based on the response via ajax.

👤Rk..

Leave a comment