python - Accessing MultipleChoiceField choices values -
How do I get the values of the fields and not the key from the form?
I have a form where I allow the user to select some user's email for a company. For example, I have a form like this (for model form it is the reason that it is a format Is within - but it is not important for now):
class contact (forms.ModelForm): def __init__ (auto, * arg, ** quorz): super (contact, self ) .__ init __ (* args, ** kwargs) self.company = kwargs ['initial'] ['company'] self.fields ['email'] .source = self.company.e Mails # This kind of stuff is produced: # [(1, 'email@email.com'), ...] email = form. Multi-levelFoIsfield (Expected = False) Class Meta: Model = Company and I want to get a list of all selected emails in the view, something like this:
Form = contactsForm (request.POST) if form.is_valid (): Form.cleaned_data ['email'] [0] #No Production and Email any get_emails_display () No such method, for example, models, for example, a suggestion form.fields ['email']. The option does not work because it gives all the options, while I need some form.fields ['email']. ?
Any ideas, or let me know that it is not clear
this one It can not be a beautiful solution, but I imagine the display name is still available form.fields ['email']. Option so that you can loop through form.cleaned_data ['email'] and get the election name from field options.
Comments
Post a Comment