Update entry with file instance DRF, Vue.js 3 - django

I have a table that has a models.FileField in it. I'm able to create the file from a Vue.js website POST request, but when I want to update the instance I have to upload the file again.
The problem is not from Vue.js, because I can't update even using the DRF pre-built page.
How can I update the instance without having to upload the document again?

Related

Migrating Django app to use online media storage

I have a Django app running on a server. Currently user uploads are stored on the server filesystem.
I already know how to set up S3 storage. What is the best way to migrate existing uploads to S3 without breaking the API and having existing uploads still available?
These files are served to the front end in two ways:
Directly through a /media/path/to/upload endpoint:
/media/<path> django.views.static.serve
Through a viewset:
/api/v1/users/<user_pk>/items/<item_pk>/attachments/<pk>/ project.app.views.ItemAttachmentsViewSet
Does the following make sense:
Change the storage backend
Go through all model objects
Save each model object to get the files uploaded
Have /media/path go to a new view that will serve the files similar to how ItemAttachmentsViewSet does it.
? Or is there a better way?
The procedure outlined in the question was what I ended up doing, with the exception of step 4 which turned out to be unnecessary.

Type Error on uploading image files through django admin

I've created a personal website/blog with python django, and as an admin, I want to create instances of that blog based on the django model and display it to the html page accordingly. That model basically consists of a Title field, TextArea field, and Image field. My app is currently deployed on Heroku, and I'm serving images using AWS S3 Buckets. Locally, when I create a blog instance through the django admin it is successful, but when I log into the django admin onto the deployed app on Heroku, I'm getting this error:
TypeError at /admin/projects/project/add/
expected string or bytes-like object
and this is what appears in the console
was loaded over a secure connection, but contains a form that targets an insecure endpoint 'http://dpaste.com/'. This endpoint should be made available over a secure connection.
Upon further research, It seems like the Image field is not the type of text or bytes when I upload from as a djagno admin and s3 is throwing an error failed. This is just a hunch, but any ideas?
Add SSL to this domain http://dpaste.com/ it looks like does not implemented and change it to https://dpaste.com/ the error is due to unencrypted traffic in your webform

Is there any way to associate file upload with a particular model in loopback 3?

I am uploading file on this /api/containers/container/upload but I want to upload file using /api/Profile/upload. Is this possible ? Is there any way to automatically associate uploading file name with field created on Profile model ?
For example, if I am uploading file name "abc.txt", it gets automatically uploaded to server and it also inserts/updates field "image_name" on Profile model.
I am new to loopback Pls help.
-
-
-
You could do that by adding 'after remote method' hook, or 'after save' hook, so after upload and before the response is returned (or after your container was saved) you could process it and do something, like for example saving the profile picture. You can find more about that here and here.

How to auto-refresh the templates(or better views) whenever data is updated in models?

I am working on a project which sends data to django server using POST request (not through web browser) and updates data on models.
My templates just runs through all the data in models and print it in a table.
The problem here is that I've to manually refresh my page to get the updated data.
I want my page to auto-update the data entered into models.
I'm very new to django, so is there a way to achieve this?
(I'll post the codes if needed)

Django: Upload database associated file to remote server

Hello community of stack overflow.
Im having a big problem.
Well this is my scenery: I have two projects of Django, and the users model have a ImageField, When I create in both Porjects the users I want upload this field to another server, for example I have a Droplet in DigitalOcean just with apache, and I want upload all the media data in this server!
Thanks in advance!
I finally used the storage application, at the end, the system is uploading media files to AWS S3!