Beispiel #1
0
    def create(self, request, type, pk):
        type_id = TARGET_TYPE.get(type, -1)
        if type_id != -1:
            fav_obj = Favorite(user=request.user, target_type=type_id, target_id=pk)
            fav_obj.save()

            output = FavoriteListSerializer(fav_obj)
            return Response(output.data, status.HTTP_201_CREATED)
        else:
            return Response(status=status.HTTP_400_BAD_REQUEST)
Beispiel #2
0
def create_favorite(user):
    # create category
    cat = IngredientCategory(name='test')
    cat.save()

    # create ingredient
    ingre = Ingredient(name='test', category=cat, image=None)
    ingre.save()

    fav = Favorite(user=user, target_type=TARGET_TYPE.get('ingredient'), target_id=1)
    fav.save()
    return fav
Beispiel #3
0
    def create(self, request, type, pk):
        type_id = TARGET_TYPE.get(type, -1)
        if type_id != -1:
            fav_obj = Favorite(user=request.user,
                               target_type=type_id,
                               target_id=pk)
            fav_obj.save()

            output = FavoriteListSerializer(fav_obj)
            return Response(output.data, status.HTTP_201_CREATED)
        else:
            return Response(status=status.HTTP_400_BAD_REQUEST)
Beispiel #4
0
def create_favorite(user):
    # create category
    cat = IngredientCategory(name='test')
    cat.save()

    # create ingredient
    ingre = Ingredient(name='test', category=cat, image=None)
    ingre.save()

    fav = Favorite(user=user,
                   target_type=TARGET_TYPE.get('ingredient'),
                   target_id=1)
    fav.save()
    return fav