Momentum logo
Team 8 Classroom

๐Ÿ Search, Uploads, & Automatic Deploys ๐Ÿ

Posted on Jul 26th, 2021

Todayโ€™s Topics

  • Postgres full-text search
  • Automatic deploys with Herokuโ€™s GitHub integration
  • File upload and Amazon S3

๐ŸŽฏ Project: QuestionBox is due on Thursday

By today you should have working endpoints for:

  • login and logout
  • registration
  • all questions
  • all questions for a single user (authenticated user; own questions only)
  • all answers for a single user (authenticated user; own answers only)
  • create a question (authenticated users only)
  • details for a single question
  • all answers for a single question
  • create an answer for a question (authenticated users only)

Depending on how youโ€™ve constructed your API, you might have separate endpoints for all of the above, or you might have fewer endpoints (for instance, if you nested answers in the question detail endpoint). What matters is that your have endpoints your front-end team can use to access this data.

This week you should work on endpoints for:

  • search all questions
    • optionally search questions and answers
  • delete a question (for user who created the question)
  • mark an answer as accepted (only if you are the author of the associated question)
  • favorite/โ€starโ€ a question (authenticated users only)

๐Ÿ“– Read | ๐Ÿ“บ Watch | ๐ŸŽง Listen

๐Ÿ”– Resources

@action decorator in ViewSets

File uploads

POST with upload using Insomnia

  • choose binary file attachment
  • headers (this example assumes an image file in jpeg format, named profile-photo .jpg):

    Content-Type: image/jpeg
    Content-Disposition: attachment; filename=profile-photo.jpg
    

For more information on the values for Content-Type:

CORS for file upload

Assuming you are using django-cors-headers, youโ€™ll need to add the following to settings.py:


from corsheaders.defaults import default_headers

CORS_ALLOW_HEADERS = list(default_headers) + [
    'content-disposition',
]

Back to home