Mohamed Feddad

72%
Flag icon
The API looks great, except for the security risk of exposing the user model's primary key publicly. Thankfully, the serializers can be changed to add fields that are not present in the model, as the following code demonstrates: class PostSerializer(serializers.ModelSerializer):     posted_by = serializers.SerializerMethodField()       def get_posted_by(self, obj):         return obj.posted_by.username       class Meta:         model = models.Post         fields = ("posted_by", "message",) The SerializerMethodField is a read-only field that gets its value from a class method.
Django Design Patterns and Best Practices: Industry-standard web development techniques and solutions using Python, 2nd Edition
Rate this book
Clear rating