本文整理汇总了Python中snippets.serializers.SnippetSerializer.save方法的典型用法代码示例。如果您正苦于以下问题:Python SnippetSerializer.save方法的具体用法?Python SnippetSerializer.save怎么用?Python SnippetSerializer.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类snippets.serializers.SnippetSerializer
的用法示例。
在下文中一共展示了SnippetSerializer.save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: snippet_detail
# 需要导入模块: from snippets.serializers import SnippetSerializer [as 别名]
# 或者: from snippets.serializers.SnippetSerializer import save [as 别名]
def snippet_detail(request, month, year):
"""
Retrieve, update or delete a code snippet.
"""
try:
#snippet = Analysis.objects.filter(created__month=month,created__year=year,created__day=4,created__hour__gte=9)
snippet = Analysis.objects.filter(user_id__contains = 1030)
except Analysis.DoesNotExist:
return HttpResponse(status=404)
if request.method == 'GET':
serializer = SnippetSerializer(snippet, many=True)
return JSONResponse(serializer.data)
elif request.method == 'PUT':
data = JSONParser().parse(request)
serializer = SnippetSerializer(snippet, data=data)
if serializer.is_valid():
serializer.save()
return JSONResponse(serializer.data)
return JSONResponse(serializer.errors, status=400)
elif request.method == 'DELETE':
snippet.delete()
return HttpResponse(status=204)
示例2: snippet_detail
# 需要导入模块: from snippets.serializers import SnippetSerializer [as 别名]
# 或者: from snippets.serializers.SnippetSerializer import save [as 别名]
def snippet_detail(request, pk):
"""
코드 조각 조회, 업데이트, 삭제
"""
try:
snippet = Snippet.objects.get(pk=pk)
except Snippet.DoesNotExist:
return HttpResponse(status=404)
if request.method == 'GET':
serializer = SnippetSerializer(snippet)
return JSONResponse(serializer.data)
elif request.method == 'PUT':
data = JSONParser().parse(request)
serializer = SnippetSerializer(snippet, data=data)
if serializer.is_valid():
serializer.save()
return JSONResponse(serializer.data)
return JSONResponse(serializer.errors, status=400)
elif request.method == 'DELETE':
snippet.delete()
return HttpResponse(status=204)
示例3: post
# 需要导入模块: from snippets.serializers import SnippetSerializer [as 别名]
# 或者: from snippets.serializers.SnippetSerializer import save [as 别名]
def post(self,request):
data = JSONParser().parse(request)
serializer = SnippetSerializer(data=data)
if serializer.is_valid():
serializer.save()
return JSONResponse(serializer.data,status=201)
return JSONResponse(serializer.errors,status=400)
示例4: post
# 需要导入模块: from snippets.serializers import SnippetSerializer [as 别名]
# 或者: from snippets.serializers.SnippetSerializer import save [as 别名]
def post(self, request, format=None):
serializer = SnippetSerializer(data=request.data)
if serializer.is_valid():
# The create() method of our serializer will now be passed an additional 'owner' field, along with the validated data from the request.
serializer.save(owner=self.request.user)
return Response(serializer.data, status=status.HTTP_201_CREATED)
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
示例5: snippet_detail_api
# 需要导入模块: from snippets.serializers import SnippetSerializer [as 别名]
# 或者: from snippets.serializers.SnippetSerializer import save [as 别名]
def snippet_detail_api(request, id):
"""
Retrieve, update or delete a code snippet.
"""
try:
snippet = Snippet.objects.raw_query({'rea' : int(id)})
# print JSONResponse(snippet.data)
except Snippet.DoesNotExist:
return HttpResponse(status=404)
if request.method == 'GET':
if snippet:
all_avisos = snippet.values('rea')[0]
serializer = SnippetSerializer(all_avisos)
return JSONResponse(serializer.data)
else:
all_avisos = [{"Message":"No duplicated ads found."}]
return JSONResponse(all_avisos)
elif request.method == 'PUT':
data = JSONParser().parse(request)
serializer = SnippetSerializer(snippet, data=data)
if serializer.is_valid():
serializer.save()
return JSONResponse(serializer.data)
return JSONResponse(serializer.errors, status=400)
elif request.method == 'DELETE':
snippet.delete()
return HttpResponse(status=204)
示例6: snippet_detail
# 需要导入模块: from snippets.serializers import SnippetSerializer [as 别名]
# 或者: from snippets.serializers.SnippetSerializer import save [as 别名]
def snippet_detail(request, pk, format=None):
"""
Retrieve, update or delete a code snippet.
"""
try:
snippet = Snippet.objects.get(pk=pk)
except Snippet.DoesNotExist:
return HttpResponse(status=404)
if request.method == 'GET':
serializer = SnippetSerializer(snippet)
return Response(serializer.data)
elif request.method == 'PUT':
#use resquest.data repalce data
#data = JSONParser().parse(request)
serializer = SnippetSerializer(snippet, data=resquest.data)
if serializer.is_valid():
serializer.save()
return Response(serializer.data)
return Response(serializer.errors, status=400)
elif request.method == 'DELETE':
snippet.delete()
return HttpResponse(status=204)
示例7: snippet_detail
# 需要导入模块: from snippets.serializers import SnippetSerializer [as 别名]
# 或者: from snippets.serializers.SnippetSerializer import save [as 别名]
def snippet_detail(request, pk, format=None):
"""
Retrieve, update or delete a code snippet.
"""
try:
snippet = Snippet.objects.get(pk=pk)
except Snippet.DoesNotExist:
return Response(status=status.HTTP_404_NOT_FOUND)
if request.method == 'GET':
serializer = SnippetSerializer(snippet)
return Response(serializer.data)
elif request.method == 'PUT':
# data = JSONParser().parse(request)
# serializer = SnippetSerializer(snippet, data=data)
serializer = SnippetSerializer(snippet, data=request.DATA)
if serializer.is_valid():
serializer.save()
return Response(serializer.data)
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
elif request.method == 'DELETE':
snippet.delete()
return Response(status=status.HTTP_200_OK)
示例8: snippet_detail
# 需要导入模块: from snippets.serializers import SnippetSerializer [as 别名]
# 或者: from snippets.serializers.SnippetSerializer import save [as 别名]
def snippet_detail(request, pk):
"""
Retrieve, update or delete a snippet instance.
"""
try:
snippet = Snippet.objects.get(pk=pk)
except Snippet.DoesNotExist:
return Response(status=status.HTTP_404_NOT_FOUND)
if request.method == 'GET':
serializer = SnippetSerializer(snippet)
return Response(serializer.data)
elif request.method == 'PUT':
serializer = SnippetSerializer(snippet, data=request.DATA)
if serializer.is_valid():
serializer.save()
return Response(serializer.data)
else:
return Response(serializer.errors,
status=status.HTTP_400_BAD_REQUEST)
elif request.method == 'DELETE':
snippet.delete()
return Response(status=status.HTTP_204_NO_CONTENT)
示例9: snippet_detail
# 需要导入模块: from snippets.serializers import SnippetSerializer [as 别名]
# 或者: from snippets.serializers.SnippetSerializer import save [as 别名]
def snippet_detail(request, pk):
"""
Retrieve, update, or delete a code snippet.
:param request:
:param pk:
:rtype: JSONResponse
:return:
"""
try:
snippet = Snippet.objects.get(pk=pk)
except Snippet.DoesNotExist:
return HttpResponse(status=404)
if request.method == 'GET':
serializer = SnippetSerializer(snippet)
return JSONResponse(serializer.data)
elif request.method == 'PUT':
data = JSONParser().parse(request)
serializer = SnippetSerializer(snippet, data=data)
if serializer.is_valid():
serializer.save()
return JSONResponse(serializer.data)
return JSONResponse(serializer.errors, status=400)
elif request.method == 'DELETE':
snippet.delete()
return HttpResponse(status=204)
示例10: put
# 需要导入模块: from snippets.serializers import SnippetSerializer [as 别名]
# 或者: from snippets.serializers.SnippetSerializer import save [as 别名]
def put(self, request, pk, format=None):
snippet = self.get_object(pk)
serializer = SnippetSerializer(snippet, data=request.data)
if serializer.is_valid():
serializer.save()
return Response(serializer.data)
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
示例11: snippet_detail
# 需要导入模块: from snippets.serializers import SnippetSerializer [as 别名]
# 或者: from snippets.serializers.SnippetSerializer import save [as 别名]
def snippet_detail(request, pk):
"""
Retrieve, update or delete a code snippet.
"""
try:
snippet = Snippet.objects.get(pk=pk)
except Snippet.DoesNotExist:
return HttpResponse(status=404)
if request.method == 'GET':
serializer = SnippetSerializer(snippet)
return JSONResponse(serializer.data)
elif request.method == 'PUT':
data = JSONParser().parse(request)
serializer = SnippetSerializer(snippet, data=data)
if serializer.is_valid():
serializer.save()
return JSONResponse(serializer.data)
return JSONResponse(serializer.errors, status=400)
elif request.method == 'DELETE':
snippet.delete()
return HttpResponse(status=204)
permission_classes = (permissions.IsAuthenticatedOrReadOnly,)
permission_classes = (permissions.IsAuthenticatedOrReadOnly,
IsOwnerOrReadOnly,)
示例12: post
# 需要导入模块: from snippets.serializers import SnippetSerializer [as 别名]
# 或者: from snippets.serializers.SnippetSerializer import save [as 别名]
def post(self, request, format=None):
serializer = SnippetSerializer(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)
示例13: snippet_detail
# 需要导入模块: from snippets.serializers import SnippetSerializer [as 别名]
# 或者: from snippets.serializers.SnippetSerializer import save [as 别名]
def snippet_detail(request, id):
"""
Retrieve, update or delete a code snippet.
"""
try:
snippet = Snippet.objects.raw_query({'rea' : int(id)})
if not snippet:
return HttpResponse(status=404)
all_avisos = snippet.values('rea')[0]
except Snippet.DoesNotExist:
return HttpResponse(status=404)
if request.method == 'GET':
serializer = SnippetSerializer(all_avisos)
context = {'duplicateds_avisos': all_avisos['rea']}
return render(request, 'duplicateds.html', context)
elif request.method == 'PUT':
data = JSONParser().parse(request)
serializer = SnippetSerializer(snippet, data=data)
if serializer.is_valid():
serializer.save()
return JSONResponse(serializer.data)
return JSONResponse(serializer.errors, status=400)
elif request.method == 'DELETE':
snippet.delete()
return HttpResponse(status=204)
示例14: snippet_list
# 需要导入模块: from snippets.serializers import SnippetSerializer [as 别名]
# 或者: from snippets.serializers.SnippetSerializer import save [as 别名]
def snippet_list(request):
if request.method == "GET":
snippets = Snippet.objects.all()
serializer = SnippetSerializer(snippets, many=True)
return Response(serializer.data)
elif request.method == "POSt":
serializer = SnippetSerializer(data=request.data)
if serializer.is_valid():
serializer.save()
return Response(serializer.data, status=status.HTTP_100_CONTINUE)
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
示例15: snippet_list
# 需要导入模块: from snippets.serializers import SnippetSerializer [as 别名]
# 或者: from snippets.serializers.SnippetSerializer import save [as 别名]
def snippet_list(request):
if request.method == 'GET':
snippets = Snippet.objects.all()
serializer = SnippetSerializer(snippets,many=True)
return Response(serializer.data)
elif request.method == 'POST':
serializer = SnippetSerializer(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_404_BAD_REQUEST)