I have a selectmultiple choice widget that gets data from mysql database and displays to the user.
list = [(x.pk, x.parameter) for x in Parameter.objects.all()]
parameters = forms.CharField(label=("Available parameters"),widget=forms.SelectMultiple(choices=list)
For example, currently it will show like [A,B,C] in its choices.
If I delete ‘B’ directly from the database, I should be able to see only [A,C] in the selectmultiple widget(initially I thought there will be a reload and get data from database again), but that doesn’t seem to be the case, it will still display [A,B,C]. I want the selectmultiplet widget to actually show the current database at runtime, or refresh(F5) the page at least {seems to not refresh the widget too}. It will only get the new set of data if I restart the web server.
I think it might be some cache that I need to clear? Appreciate any suggestions.
Thanks
You need to put your code in the init method of the form, or pass the choices to the form on form creation: