Reputation: 43
I have a choice field on a form which allows the user to select a table from within my postgres database. Using the development server this is populated during the runserver command. The problem I have is I would like the choice field to update with new tables which may be created by user. At present the only way to make new tables available in the choice field is to start and stop the server. Is there a way this can be done automatically?
Upvotes: 4
Views: 2170
Reputation: 6359
Define a custom __init__
method on your form. Call super(MyForm, self).__init__(*args, **kwargs)
, and then set self.fields["thechoicefield"].choices
when you initialize the form.
Upvotes: 6