I have multiple models that have a field created by(Foreign key to user) in them. After making serializers for the models, i wanted that the created field be required at the time of object creation but once the object is created the field becomes read only.
Is there anyway to do this. For the sake of context below is an example code.
class Test(model.Model):
...
created_by = model.ForeignKey(User)
....
class TestSerializer(serializer.Serializer):
# other fields
created_by = serializer.SlugRelatedField(queryset = User.objects.all(), slug_field="username")
And after the Test object is created, any further put request will skip the required = True(Like it is done for partial_update by making partial = true) validation for that particular instance.