I am using Django 2.2 and Pillow library in the models fields to handle the image files.
I studied a latest online course on Django where tutor used special method during image save to make sure that similarly named images will not override .
But I noticed that when a user upload two different images with same name , Django renames the second file without any function and the files never conflicted when we retrieve.
Is this a new feature in Django ? Should I follow file renaming convention ?
Related
I want to create the file(.wav) by django and let it be downloaded by user.
Currently I create the file under /myproj/static directory.
However it is mixed with the other jpg/img files, so,, it's not good design?
then, I read the document about /myproj/media directory but it is said used for user upload files.
So,,, how is the good directory design for server created file?
Should I create such as /myproj/create_wav?
but how can user access this url in template?
Thank you for any idea or helps.
According to Django's documentation,
By default, Django stores files locally, using the MEDIA_ROOT and MEDIA_URL settings. (...) However, Django provides ways to write custom file storage systems that allow you to completely customize where and how Django stores files.
So, in OP's shoes I'd simply use the media folder, since that's used not only for user uploads but also for user downloads.
I am trying to create a picture slideshow which will show all the png and jpg files of a folder using django.
Problem is how do I open windows explorer through django and prompt user to choose a folder name to load images from. Once this is done, how do I read all image files from this folder? Can I store all image files from this folder inside a list and pass this list in template views through context?
This link “https://github.com/csev/dj4e-samples/tree/master/pics”
shows how to store data into to database(sqlite is the database used here) using Django forms. But you cannot upload an entire folder at once, so you have to create a one to many model between display_id(This is just a field name in models you can name it anything you want) and pics. Now you can individually upload all pics in the folder to the same display _id and access all of them using this display_id. Also make sure to pass content_type for jpg and png separately while retrieving the pics.
I have a method that creates a csv file from a serialized model and writes the file to a data folder. This works - the csv is created, but to do anything with it a user has to manually upload it back in to the app, which is awkward.
I'd like to automate the step of uploading that same file to the UploadFile model in another app within the same project - that is, when it is created, instead of, or in addition to, being written to the file tree, the file is uploaded and stored in a FileField (or location anyway) in an UploadedFile.
EDIT: In this app - a user fills out several forms which, taken together, create a Group. The Group model has a many-2-many relationship to a People model, which has many-2-many relationships to the Attribute and Stats models. Each model has an associated form.
So a user would create a Group, submit it which writes it to the data folder, and then -<(magic happens)>- the Group.name, Group.label, and Group.data are applied to the UploadFileForm which uploads it to the UploadFile model.
I have searched google for something like this and found nothing -- which makes me think I am forming the question incorrectly. Any help is appreciated.
I'll post my code if need be, but a general solution would be helpful enough.
EDIT: I realize now that I can't use 'initial' to populate a FileField in a django mode -- security risk. Since that won't work - I'm out of ideas for how to upload the last file created to a FileField in a django model by any means.
I am impressed with how wordpress handle the images (where user can upload and insert images into post). I want to make this feature to able applied in django. How do I achieve it?
Basically I have two models :
1.post - for writing the content
2.media - for uploading images/files
But in the post model I would like to able insert the images from the media model in the textField(). For the textField I am using django-tinymce for rich text context with filebrowser integration. So, better use the Image button to upload/insert image to/from media model.
Also the user only allow to browse the images that he/she uploaded in the filebrowser.
Lastly beside in the admin, this feature also need to work in frontend.
So is this possible?
I am creating an application in django where I want to upload multiple file from django admin. I also want these files to be associated with a particular user in my database. for e.g a pdf file will have a file names as 'john.pdf', 'matt.pdf', 'alice.pdf' and I want to upload all these files at once from django admin and each file should be associated with particular user, so if user john logs in he can see pdf 'john.pdf' in his profile page.
I am new to django and web programming and I have been banging my head for a couple of days but I just cannot find the right logic to implement such a code.
I have looked in these resources but I still cannot really find an answer
How to upload multiple file in django admin models
How to upload through django admin.
I am using django with mysql database. I highly appreciate and thank anyone in advance who could help me out with this problem. (hoping not to get downvoted too much)
Ok so I found out a solution but I still don't know if thats the best solution there. What I did was to add path of my pdf files in MySQL database and add attributes to those paths. I wrote a script in python to add those files to MySQL database. My script listed all the files in the directory, where the files were stored and added them to the database. From these attributes I could retrieve those paths. As these are just paths to static files I had to save them in the static folder for django to access and display them and the rest was simple.