1π
I had a similar issue where i want to store file to s3 either directly using FileField or i have an option for the user to input the url directly. So to circumvent that, i used 2 fields in my model, one for FileField and one for URLField. And in the template i could use βorβ to see which one exists and to use that like {{ instance.filefield or instance.url }}.
- Managing multiple settings.py files
- Django form dropdown with all users in it
- Unit-testing Python: Mocking function calls inside function
1π
This is untested, but you should be able to use:
from django.core.files.storage import default_storage
f = default_storage.open('name_you_expect_in_s3', 'r')
#f is an instance of S3BotoStorageFile, and can be assigned to a field
obj, created = YourObject.objects.get_or_create(**stuff_you_know)
obj.s3file_field = f
obj.save()
I think this should set up the local pointer to s3 and save it, without over writing the content.
ETA: You should do this only after the upload completes on S3 and you know the key in s3.
- Django time difference with F object
- Can i get models field type from a model queryset in Django?
- How to return data with 403 error in Django Rest Framework?
- Django datetime field β convert to timezone in view
- Reverse() argument after ** must be a mapping
- Deploying Django Channels with Daphne + NGINX using SSL
- How do I add custom actions to a change model form in Django Admin?
-1π
Iβve never used django, so ymmv π but why not just write a single byte to populate the content? That way, you can still use FieldFile.
-1π
Iβm thinking that writing actual SQL may be the easiest solution here. Alternatively you could subclass S3BotoStorage, override the _save method and allow for an optional kwarg of filepath which sidesteps all the other saving stuff and just returns the cleaned_name.
- Whats the best way to duplicate data in a django template?
- AssertionError at /posts/ 'PostList' should either include a `queryset` attribute, or override the `get_queryset()` method
- Restricting all the views to authenticated users in Django