First time using Django Forms. I'm stuck trying to get the dropdown choices to reload. My forms.py is below. When the database state changes, the choices do not. I suppose that this is because they are defined at a class level, which means the query happens at initialisation of the module? I've found that the only way to get my dropdowns to update is to restart the webserver.
How can I have the database queries evaluate on every request?
forms.py
from django import forms
from app.models import Collection, ErrorMessage, Service
class FailureForm(forms.Form):
collections = [(collection.value,)*2 for collection in Collection.objects.all()]
error_messages = [(message.value,)*2 for message in ErrorMessage.objects.all()]
services = [(service.value,)*2 for service in Service.objects.all()]
collection = forms.CharField(label='collection', max_length=100, widget=forms.Select(choices=collections))
error_message = forms.CharField(label='error_message', max_length=400, widget=forms.Select(choices=error_messages))
service = forms.CharField(label='service', max_length=100, widget=forms.Select(choices=services))