im having to with multiple file uploads, when i tried to upload files only 1 file will be saved..
here's my code: views.py def attachments(request): to = TravelOrder.objects.order_by('-date_filling').last() if request.method == 'POST': form = AttachmentsForm(request.POST, request.FILES) if form.is_valid(): for f in request.FILES.getlist('attachment'): instance = form.save(commit=False) instance.travel_order = to instance.attachment = f instance.save() print('YEW') return redirect('attach') else: form = AttachmentsForm() context = { 'form': form } return render(request, 'employee/attachments.html', context) models.py class TravelOrder(models.Model): created_by = models.CharField(max_length=255) start_date = models.DateField(auto_now=False) end_date = models.DateField(auto_now=False) wfp = models.CharField(max_length=255, verbose_name='Wfp Where to be charged') purpose_of_travel = models.CharField(max_length=255) region = models.ForeignKey(Region, on_delete=models.CASCADE) venue = models.CharField(max_length=255) date_filling = models.DateTimeField(auto_now_add=True) status = models.CharField(max_length=15) def __str__(self): return self.purpose_of_travel class Attachements(models.Model): at_id = models.AutoField(primary_key=True) travel_order = models.ForeignKey(TravelOrder, on_delete=models.CASCADE) attachment = models.FileField(upload_to='attachment/') forms.py class AttachmentsForm(forms.ModelForm): class Meta: model = Attachements exclude = ['travel_order'] fields = ('attachment',) widgets = { 'attachment': forms.ClearableFileInput(attrs={'multiple':True}) } hope you can help me guys. thank you.. -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/6d59b634-b6d9-4597-b502-012de4ac3c89%40googlegroups.com.