File tree 1 file changed +11
-2
lines changed
1 file changed +11
-2
lines changed Original file line number Diff line number Diff line change
1
+ from typing import Optional
2
+
1
3
import warnings
2
4
from functools import partial
3
5
@@ -51,6 +53,13 @@ def validate_comma_separated_emails(value):
51
53
for v in value .split ("," ):
52
54
validate_email (v .strip ())
53
55
56
+ def email_field_choices (form : Optional [forms .ModelForm ], required : bool = True ) -> list [tuple [str , str ]]:
57
+ if not form or not form .instance or not form .instance .pk :
58
+ return []
59
+ email_fields = form .instance .fields .filter (type = 'email' )
60
+ choices = [] if required else [('' , '--' )]
61
+ choices .extend ([(_ .name , _ .title ) for _ in email_fields ])
62
+ return choices
54
63
55
64
class Form (models .Model ):
56
65
CONFIG_OPTIONS = [
@@ -86,13 +95,13 @@ class Form(models.Model):
86
95
),
87
96
(
88
97
"author_email_field" ,
89
- forms .CharField (
98
+ forms .ChoiceField (
90
99
label = capfirst (_ ("author's email field" )),
91
100
help_text = _ (
92
101
"The author of the submission will be added to the Cc: if this is set to an existing form field below."
93
102
),
94
103
required = False ,
95
- widget = widgets . AdminTextInputWidget ,
104
+ choices = email_field_choices ( form , required = False ) ,
96
105
),
97
106
),
98
107
],
You can’t perform that action at this time.
0 commit comments