Django sterilizer update method validated_data convertion
I am trying to update an instance of my model via the serializer update method.
This modal have many to many connection to another model.
my models:
class GPX(models.Model):
name = models.CharField(max_length=255)
created_date = models.DateField(auto_now_add=True)
updated_date = models.DateField(auto_now=True)
trail_types = models.ManyToManyField(TrailTypes, blank=True)
class TrailTypes(models.Model):
name = models.CharField(max_length=100)
def __str__(self):
return self.name
I want to get has input a list contain trail_types names instead of their ids.
The problem is that Django converts the data objects of trail_types and then pass it as validate_data to the update method under the seralizer.
How can I do the conversion before? or is there another way to specify to Django to create trail_type objects by its name.
@transaction.atomic
def update(self, instance, validated_data):
gpx: GPX = super().update(instance, validated_data)
return gpx
thanks in advanced