Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

184
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda