django-file-upload

Django : customizing FileField value while editing a model

送分小仙女□ 提交于 2019-12-31 22:25:31
问题 I've got a model, with FileField . When I edit this model in a view, I want to change the "current" value of FileField which gets displayed in the view form. Let me explain. models.py: class DemoVar_model(models.Model): ... Welcome_sound=models.FileField(upload_to='files/%Y/%m/%d') forms.py: class DemoVar_addform(ModelForm): ... class Meta: model = DemoVar_model views.py: soundform = DemoVar_addform(instance=ivrobj) .... return render_to_response(template,{'soundform':soundform}, ....) Now I

Allow users to download files directly django

不问归期 提交于 2019-12-24 19:29:41
问题 In the TrainerProfileModel I have file field called cv. I want to allow users to download the file directly when clicking on the link. Could you provide any ways to implement this? models.py: class TrainerProfile(models.Model): user = models.OneToOneField(User, on_delete=models.CASCADE, null=True, related_name='trainer_profile') profile_picture = models.ImageField(blank=True) phone_regex = RegexValidator(regex=r'^\+?1?\d{9,15}$', message="Phone number must be entered in the format: '

Using a Django FileField in an inline formset

守給你的承諾、 提交于 2019-12-24 11:17:04
问题 having issues getting the file to upload in my app. A User submits a report and can add attachments (through a foreign key relationship). I've got the inline form showing up and will work if I leave it blank, but when I try to upload a file then submit the form I get a 500 error. The base report is made, but the attachment that's getting inlined doesn't get saved. forms.py class ReportForm(forms.ModelForm): accidentDate = forms.DateField(widget=SelectDateWidget( empty_label=("Choose Year",

save multiple uploaded files in django

我与影子孤独终老i 提交于 2019-12-22 04:36:25
问题 I want to upload and save multiple files in my application, I have <input type="text" name="name" value="" /> <input type="file" name="file" multiple/> in my template. when I hit upload, seems form = MyForm(request.POST, request.FILES) is only saving one file which is last in the list of the many uloaded files. How can I be able to save all the uploaded files using the form form = MyForm(request.POST, request.FILES) blah blah ? Thanks Edit Myform is a model form from this model. class Docs

Trying to use django and dropzone/

跟風遠走 提交于 2019-12-20 14:45:49
问题 I'm trying to use dropzone.js with django. I'm following the somewhat dated guide here (https://amatellanes.wordpress.com/2013/11/05/dropzonejs-django-how-to-build-a-file-upload-form/) I strongly suspect My view is at issue. def test(request): print "test view has been called" if request.method == 'POST': print "test request method is POST" form = UploadFileForm(request.POST, request.FILES) print request print request.FILES if form.is_valid(): new_file = AttachedFiles(attachedfile=request

How to limit file types on file uploads for ModelForms with FileFields?

时光总嘲笑我的痴心妄想 提交于 2019-12-17 15:43:26
问题 My goal is to limit a FileField on a Django ModelForm to PDFs and Word Documents. The answers I have googled all deal with creating a separate file handler, but I am not sure how to do so in the context of a ModelForm. Is there a setting in settings.py I may use to limit upload file types? 回答1: I handle this by using a clean_[your_field] method on a ModelForm. You could set a list of acceptable file extensions in settings.py to check against in your clean method, but there's nothing built

Copy file into another folder with django?

瘦欲@ 提交于 2019-12-12 20:34:14
问题 I need to upload profile images into diferent folders in Django. So, I have a folder for each account, and the profile image have to go to the specific folder. How can I do that? Here is my uploadprofile.html <form action="{% url 'uploadimage' %}" enctype="multipart/form-data" method="POST"> {% csrf_token %} <input type="file" name="avatar" accept="image/gif, image/jpeg, image/png"> <button type="submit">Upload</button> </form> And here is my view in views.py def uploadimage(request): img =

django file upload - image deleted when edit template updated

[亡魂溺海] 提交于 2019-12-12 02:04:45
问题 I am using django to allow a user to upload images along with text to describe the image title. The user should be able to edit the image title and change the image file using the edit template. This does work - to some degree. I can display the image file and the image title in the edit template for editing. The issue I have is when I do not include an image file in the file upload input (the user only wants to change the image title and not the image file), the code I have does change the

Keeping Original Filename for FileField in Django

点点圈 提交于 2019-12-11 09:38:59
问题 I would like to keep the original file name of an UploadedFile in Django that has its location stored in a FileField . Right now I am observing that if two files have the same name, the first file uploaded keeps its original name but the second time a file with that name is uploaded, it has a random string appended to make the file name unique. One solution is to add an additional field to the model: Django: How to save original filename in FileField? or Saving Original File Name in Django

Django - User uploaded S3 files in the view

南笙酒味 提交于 2019-12-11 09:24:58
问题 I have a page where users can upload PDF / image files to their profile. The model for these files is relativly straightforward: class ResumeItemFile(models.Model): item = models.ForeignKey(ResumeItem, related_name='attachment_files') file = models.FileField( max_length=255, upload_to=RandomizedFilePath('resume_attachments'), verbose_name=_('Attachment')) name = models.CharField(max_length=255, verbose_name=_('Naam'), blank=True) I am creating a view where all files linked to a profile ( item