我想django-rest-framwork
在保存之前编辑一个序列化程序对象。这就是我目前的做法 -
def upload(request):
if request.method == 'POST':
form = ImageForm(request.POST, request.FILES)
if form.is_valid(): # All validation rules pass
obj = form.save(commit=False)
obj.user_id = 15
obj.save()
如何使用django-rest-framework
序列化程序对象来做到这一点?
@api_view(['POST','GET'])
def upload_serializers(request):
if request.method == 'POST':
serializer = FilesSerializer(data=request.DATA, files=request.FILES)
if serializer.is_valid():
serializer.save()