Skip to content

Instantly share code, notes, and snippets.

@ewelina29
Created April 10, 2021 19:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ewelina29/bc1a789b965a72747d6f50f67d63da4c to your computer and use it in GitHub Desktop.
Save ewelina29/bc1a789b965a72747d6f50f67d63da4c to your computer and use it in GitHub Desktop.
class PizzaSerializer(serializers.ModelSerializer):
selected_sauce = serializers.CharField(source="sauce.name", read_only=True)
selected_ingredients = IngredientSerializer(many=True, source="ingredients", read_only=True)
class Meta:
model = Pizza
fields = '__all__'
extra_kwargs = {
'sauce': {'write_only': True},
'ingredients': {'write_only': True}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment