Exemple #1
0
 def put(self, request, id, format=None):
     cat = self.get_object(id)
     serializer = CategorySerializer(cat, data=request.data)
     if serializer.is_valid():
         serializer.save()
         return Response(serializer.data)
     return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
    def post(self, request, format=None):
        cat = request.data['category']

        if 'color' in request.data.keys():
            color = request.data['color']
        else:
            color = '#F8A055'

        try:
            c = Category.objects.get(title__iexact=cat, owned_by=request.user)
        except Category.DoesNotExist:
            c = Category(title=cat, owned_by=request.user, color=color)
            c.save()

        serializer = CategorySerializer(c)
        return Response(serializer.data)
    def post(self, request, format=None):
        old_cat = request.data['old']
        new_cat = request.data['updated']

        try:
            c = Category.objects.get(title=old_cat, owned_by=request.user)
        except Category.DoesNotExist:
            raise Http404

        if 'color' in request.data.keys():
            c.color = request.data['color']

        c.title = new_cat
        c.save()

        serializer = CategorySerializer(c)
        return Response(serializer.data)
Exemple #4
0
 def get(self, request, id, format=None):
     cat = self.get_object(id)
     serializer = CategorySerializer(cat)
     return Response(serializer.data)
Exemple #5
0
 def post(self, request, format=None):
     serializer = CategorySerializer(data=request.data)
     if serializer.is_valid():
         serializer.save()
         return Response(serializer.data, status=status.HTTP_201_CREATED)
     return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
Exemple #6
0
 def get(self, request, format=None):
     cats = Category.objects.all()
     serializer = CategorySerializer(cats, many=True)
     return Response(serializer.data)
Exemple #7
0
class LoginSerializer(serializers.Serializer):
    token = serializers.CharField(max_length=100)
    key = serializers.CharField()
    md5 = serializers.CharField()
    categories = CategorySerializer(many=True)
    tracking = serializers.BooleanField()
 def get(self, request, format=None):
     c = Category.objects.filter(owned_by=request.user)
     serializer = CategorySerializer(c, many=True)
     return Response(serializer.data)