Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

188
Visualizações
Django form is adding characters when I am editing details

Here is how my form is set up (all the fields are the same):

class AddColourForm(forms.Form):

    colour = forms.CharField(
        widget=TextInput(attrs={'class':'form-control'}),
        max_length=100,
        required=False,
        label = "Colour:",
    )

Here is my view:

if form.is_valid():
    selected_colour.code = form.cleaned_data['code'],
    selected_colour.name = form.cleaned_data['colour'],
    selected_colour.save()

Here is what happens when it goes into the db:

(u'red',) (u'#ff0000',)

I have tried adding unicode() wrappers around the cleaned data before saving but that isn't working.

Does anyone have any other suggestions?

about 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

Try removing the commas after each line like so (they aren't necessary):

selected_colour.code = form.cleaned_data['code']
selected_colour.name = form.cleaned_data['colour']
selected_colour.save()

it looks like the commas are turning your data into a list.

about 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda