Доброе утро, отправляю данные с фронта
export function addProject(typeProject) {
axios.post("http://127.0.0.1:8000/add_project/", {
userId: window.localStorage.getItem("userId"),
typeProject: typeProject
})
.then(res => {
console.log(res);
})
.catch(error => {
console.log(error)
});
}
route
router.register(r'add_project', AddProjectView)
views
class AddProjectView(mixins.CreateModelMixin, mixins.RetrieveModelMixin,
mixins.UpdateModelMixin, viewsets.GenericViewSet):
queryset = Project.objects.all()
serializer_class = ProjectSerializer
authentication_classes = (TokenAuthentication,)
def put(self, request):
"""Create project."""
instance = self.queryset
return self.update(request, instance=instance)
serializer
class ProjectSerializer(serializers.ModelSerializer):
class Meta:
model = Project
fields = ('name', 'projecttype')
def update(self, instance, validated_data):
"""
Create the object.
:param instance:
:param validated_data: string
"""
user_id = validated_data["userId"]
user = User.objects.get(id=user_id)
print(user)
user_account = UserAccount.objects.get(user=user)
customer = Customer.objects.get(useraccount=user_account)
instance.customer = customer
instance.name = "PROJECT 001"
instance.projecttype = validated_data["typeProject"]
instance.save()
return instance
Вроде все понятно, но не работает. Возвращает ошибку 400. Подскажите где ошибка