We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Describe the bug A clear and concise description of what the bug is.
#model.py class Department(models.Model): title = models.CharField(max_length=100)
class Employee(models.Model): first_name = models.CharField(max_length=100) last_name = models.CharField(max_length=100) department = models.ForeignKey(Department, on_delete=models.CASCADE, null=True, blank=True) birthdate = models.DateField(null=True, blank=True) cv = models.FileField(upload_to='cvs', null=True, blank=True)
class EmployeeIn(Schema): first_name: str last_name: str department_id: Union[int, str, None] = Field( default=None, description="Department ID", exclude_none=True ) birthdate: Union[date, str, None] = Field( default=None, description="Birthdate in the format yyyy-mm-dd", exclude_none=True ) @field_validator('department_id', 'birthdate') @classmethod def empty_str_to_none(cls, v): if v == '': return None return v @router.put("/employees/{employee_id}") def update_employee( request, employee_id: int, payload: Form[EmployeeIn], cv: UploadedFile = File(None) ): employee = get_object_or_404(Employee, id=employee_id) for attr, value in payload.dict().items(): setattr(employee, attr, value) if cv: employee.cv.save(cv.name, cv) # will save model instance as well else: employee.save() return {"success": True}
when is use this curl -X 'PUT' 'http://127.0.0.1:8000/api/employees/1' -H 'accept: /' -H 'Content-Type: multipart/form-data' -F 'first_name=2' -F 'last_name=2' -F 'department_id=' -F 'birthdate=' -F 'cv=' this @router.put("/employees/{employee_id}") method raise
Error: Unprocessable EntityResponse bodyDownload{ "detail": [ { "type": "missing", "loc": [ "form", "first_name" ], "msg": "Field required" }, { "type": "missing", "loc": [ "form", "last_name" ], "msg": "Field required" } ] } --
use @router.post("/employees/{employee_id}") will work fine
Versions (please complete the following information):
Note you can quickly get this by runninng in ./manage.py shell this line:
./manage.py shell
import django; import pydantic; import ninja; django.__version__; ninja.__version__; pydantic.__version__
The text was updated successfully, but these errors were encountered:
same problem here, and similar on https://stackoverflow.com/questions/75971415/when-using-uploadedfile-in-the-put-method-of-ninja-router-i-get-detail post works well, put/get no
my guess is - might be issue arises due to very old version of django-ninja, i also have 0.20.0
Sorry, something went wrong.
No branches or pull requests
Describe the bug
A clear and concise description of what the bug is.
#model.py
class Department(models.Model):
title = models.CharField(max_length=100)
class Employee(models.Model):
first_name = models.CharField(max_length=100)
last_name = models.CharField(max_length=100)
department = models.ForeignKey(Department, on_delete=models.CASCADE, null=True, blank=True)
birthdate = models.DateField(null=True, blank=True)
cv = models.FileField(upload_to='cvs', null=True, blank=True)
views.py
when is use this curl -X 'PUT'
'http://127.0.0.1:8000/api/employees/1'
-H 'accept: /'
-H 'Content-Type: multipart/form-data'
-F 'first_name=2'
-F 'last_name=2'
-F 'department_id='
-F 'birthdate='
-F 'cv='
this @router.put("/employees/{employee_id}") method raise
use @router.post("/employees/{employee_id}") will work fine
Versions (please complete the following information):
Note you can quickly get this by runninng in
./manage.py shell
this line:The text was updated successfully, but these errors were encountered: