Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8910361
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T03:40:18+00:00 2026-06-15T03:40:18+00:00

I have a choice field like this in my forms.py: ASSUNTO = ( (‘1’,

  • 0

I have a choice field like this in my forms.py:

ASSUNTO = ( ('1', u'Informações'), 
        ('2', 'Comercial'), 
        ('3', 'Financeiro'), 
        ('4', 'Outro'))

In my views.py when I send the chosen value from the choice field as e-mail subject, it comes like:

Chose ‘Comercial‘ in my form in my html page

E-mail received with subject like: ‘2 – MY COMPANY‘

Code in my views.py:

from django.shortcuts import render
from forms import FormContato
from django.core.mail import send_mail


def HomeContato(request):
    form = FormContato()
    if request.method == 'POST':
        form = FormContato(request.POST)
        if form.is_valid():
            send_mail( form.cleaned_data['assunto'] + ' - MY COMPANY', 'Nome: ' + form.data['nome'] + ' ' + form.data['sobrenome'] + ' :: ' + 'E-mail: ' + form.data['email'] + ' :: ' + 'Mensagem: ' + form.data['menssagem'], 'noreply@email.com.br', ['email@gmail.com'], fail_silently=False)
            return render(request, 'contato/contato.html', locals())
        else:
            return render(request, 'contato/contato.html', locals())
    else:
        return render(request, 'contato/contato.html', locals())

How can I use this command getting the subject as: ‘Comercial – MY COMPANY’?

Thanks in advance to all!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T03:40:19+00:00Added an answer on June 15, 2026 at 3:40 am

    This isnt very pretty, but the following should do it:

    {choice[0]:choice[1] for choice in form.fields['assunto'].choices}[form.cleaned_data['assunto']]
    

    NOTE: after reading the other answer, you could do dict(form.fields['assunto'].choices)[form.cleaned_data['assunto']] – I didnt think to use a builtin function instead of a comprehension

    Also the reason you are getting “2” is that the choices tuple is a tuple of value => label tuples.

    if you want the value to not be a meaningless integer, make it like this:

    ASSUNTO = ( (u'Informações', u'Informações'), 
        ('Comercial', 'Comercial'), 
        ('Financeiro', 'Financeiro'), 
        ('Outro', 'Outro'))
    

    and then keep your view the same as you currently have it

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a multiple choice field, something like this: ft = forms.ModelMultipleChoiceField(widget=forms.CheckboxSelectMultiple) which can
I have this custom form field {# src/Acme/DemoBundle/Resources/views/Form/fields.html.twig #} {% block gender_widget %} {%
I have a form like this: class MyForm(forms.Form): [...] which is rendered in my
I have a Django my_forms.py like this: class CarSearchForm(forms.Form): # lots of fields like
I have a form like this: CHOICES = [ ('a', 'a_value'), ('b', 'b_value'), ('c',
I have a field in one of my models like the following: PAYROLL_CHOICES =
I have a handler /choice with a textarea field and /choicehandler that writes the
This might sound like an odd scenario, but I've got two forms on one
I have a model like this: class MyModel(models.Model): REGULAR = 1 PREMIUM = 2
I have a model in Django that looks like this: class Project(models.Model): name =

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.