Skip to content
New issue

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

Add a recipe for handling the file uploads #663

Merged
merged 4 commits into from
Jan 26, 2023

Conversation

barseghyanartur
Copy link
Contributor

Add a recipe for handling the file uploads.

@vitalik
Copy link
Owner

vitalik commented Jan 26, 2023

Hi @barseghyanartur

Thank you
I think you can simplify saving:

from ninja import UploadedFile, File

@api.post("/employees")
def create_employee(request, payload: EmployeeIn, cv: UploadedFile = File(...)):
    payload_dict = payload.dict()
    employee = Employee(**payload_dict)
    employee.cv.save(cv.name, cv) # will save model instance as well
    return {"id": employee.id}

@barseghyanartur
Copy link
Contributor Author

@vitalik:

Will do.

@barseghyanartur
Copy link
Contributor Author

P.S.

Shall I, perhaps, add a second recipe for when you don't work with models, but still want to upload files?

@vitalik
Copy link
Owner

vitalik commented Jan 26, 2023

Shall I, perhaps, add a second recipe for when you don't work with models, but still want to upload files?

yes - makes sense

@barseghyanartur
Copy link
Contributor Author

@vitalik:

Ready.

@vitalik
Copy link
Owner

vitalik commented Jan 26, 2023

Thank you

@vitalik vitalik merged commit 15d2401 into vitalik:master Jan 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants