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

213
Views
Django Rest Framework Serializer charfield not updating when source is given

I have a model field with choices charfield

class Vehicle(models.Model):
    name = models.CharField(max_length=100)

    STATUS_CHOICES = (
        ("N", "New"),
        ("U", "Used"),
        ("P", "Just Purchased")
    )
    status = models.CharField(max_length=3, choices=STATUS_CHOICES)

The serializer class also has charfield for status but with source argument to display the readable value

class VehicleSerializer(ModelSerializer):
    status = serializers.CharField(source='get_status_display')

    class Meta:
        model = Vehicle

When I try to update vehicles through patch request with data {'status': "U"}, there is no update performed. However the update occurs when I remove the source from serializer status field. Providing source is necessary to display proper value in web view.

I know the option of changing the name of status in serializer to something other and using that in the template. Also there is the option to override update method in serializer, however my question is what is source doing to prevent the update?

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

I think you need to add status to the fields list in meta.

class VehicleSerializer(ModelSerializer):
     status = serializers.CharField(source='get_status_display')

     class Meta:
         model = Vehicle
         fields = ('status',)
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!