Django image file not getting uploaded -
models.py
class report(models.model): user = models.foreignkey(user, null=false) photo_files_attached = models.booleanfield('photos', default=false)
forms.py
class mediaform(forms.modelform): photo_files_attached = forms.filefield(label='choose file') class meta: model = report field = ['photo_files_attached']
views.py
def media(request): user = request.user try: report = report.objects.get(user=user.id) except: report = none mediaform = mediaform() if request.method =='post': mediaform = mediaform(request.post,request.files) if mediaform.is_valid(): media = report(photo_files_attached = request.files['photo_files_attached']) media.save() return render(request, 'media.html', { 'mediaform':mediaform, })
i trying upload image file through django , save in database.once file saved ,the images collecetd in media folder in project.but not working.may know did wrong.
as far can see don't have single filefield
on model
expect uploaded files bound object?
you should either create own saving logic in within form.is_valid()
scope or use different approach overall.
here's single file example, using modelform, update forms.filefield on django forms
Comments
Post a Comment