Answer the question
In order to leave comments, you need to log in
What's wrong with POST AJAX + Django serializer request?
I am trying to edit data (current row, data in table) in api using ajax request and django serializer. I am getting a 400 error. What am I doing wrong?
Code Vue.js:
edit: function () {
let url = '/crm/customeroffice/'
let params = {'id': this.currentId,
'customer': this.inputCustomerValue,
'state': this.inputStateValue};
axios.post(url, {data: params}).then((response) => {
this.dataTable = response.data.results;
this.$refs.table.refresh();
alert("Success!");
this.closeModal();
}).catch( error => { console.log(error); })
.finally(() => (global_waiting_stop()));
},
def post(self, request, format=None):
serializer = CustomerOfficeSerializer(data=request.data)
if serializer.is_valid():
serializer.save()
return Response(serializer.data, status=201)
return Response(serializer.errors, status=400)
class CustomerOfficeSerializer(ModelSerializer):
state = StateSerializer()
customer = CustomerSerializer()
class Meta:
model = CustomerOffice
fields = ('id', 'address_id', 'customer', 'head_office', 'distributor_id', 'email', 'site', 'state', 'active')
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question