Recipes APIΒΆ

class recipes.api.recipe.RecipeViewSet(**kwargs)

Bases: rest_framework.mixins.CreateModelMixin, rest_framework.viewsets.ReadOnlyModelViewSet

This class provides the API get and retrieve views for the recipe objects. The class also uses the CreateModelMixin to provide the POST hook, and the create method is overridden to customize the creation step. I think this should probably be moved to the serializer at some point

create(request, *args, **kwargs)

The create method is overridden here to allow us to do two things: 1) verify the current user is logged in before allowing creation of a new calendar, and 2) assigning the creator attribute on the request to the currently logged in user before passing the data to the serializer. The serializer should then handle grabbing the creator instance and assigning it to the newly created calendar. I think there is something in there that would make this easier, like overriding the pre-save on the serializer or something.

Parameters:
  • request – An http request
  • args – Ordered arguments
  • kwargs – Keyword arguments
Returns:

JSONResponse with the created object or a failure message

poor_recipes(request)
queryset
serializer_class

alias of recipes.serializers.recipe.RecipeSerializer