Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

183
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!