Skip to content

Commit

Permalink
using the slug in the URL (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
RyanNoelk authored Mar 2, 2018
1 parent 337b9a5 commit 727f2d1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
7 changes: 5 additions & 2 deletions v1/recipe/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,17 @@ def to_representation(self, value):

class SubRecipeSerializer(serializers.ModelSerializer):
""" Standard `rest_framework` ModelSerializer """
slug = serializers.ReadOnlyField(source='child_recipe.slug')
title = serializers.ReadOnlyField(source='child_recipe.title')

class Meta:
model = SubRecipe
fields = (
'child_recipe_id',
'slug',
'quantity',
'measurement',
'title',
'child_recipe_id',
)


Expand All @@ -59,6 +61,7 @@ class Meta:
model = Recipe
fields = (
'id',
'slug',
'title',
'pub_date',
'rating',
Expand Down Expand Up @@ -87,7 +90,7 @@ def get_subrecipes(self, obj):

class Meta:
model = Recipe
exclude = ('slug',)
fields = '__all__'

def update(self, instance, validated_data):
"""
Expand Down
1 change: 1 addition & 0 deletions v1/recipe/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class RecipeViewSet(viewsets.ModelViewSet):
This viewset automatically provides `list`, `create`, `retrieve`,
`update` and `destroy` actions.
"""
lookup_field = 'slug'
serializer_class = serializers.RecipeSerializer
permission_classes = (permissions.IsAuthenticatedOrReadOnly,)
filter_backends = (filters.SearchFilter, filters.OrderingFilter)
Expand Down

0 comments on commit 727f2d1

Please sign in to comment.