开发者

django form choice field refresh

开发者 https://www.devze.com 2023-03-21 14:29 出处:网络
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 hav

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开发者_StackOverflow server. Is there a way this can be done automatically?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消