A
A
Alexander Reutsky2017-05-15 23:58:42
Django
Alexander Reutsky, 2017-05-15 23:58:42

Django how to attach file submissions to a feedback form?

Guys tell me there is a form 5c81e4504edb438283f3b23abbe6376a.png
How can I implement the ability to attach files (Images) in it

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey Nizhny Novgorod, 2017-05-16
@Terras

Hello:
1) You add an image storage field to the model, for example ImageField:
2) If the forms are automatically created from the model, then this field has already appeared, if you collect the forms with your hands, then you get something by type in the forms.py file:

class Profile_Form(forms.Form):
    avatar = forms.ImageField(label='Загрузить Аватар', required=False)
    myself = forms.CharField(....)
    myoffer = forms.CharField(...)

3) You set the file storage location in settings.py, for example:
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
MEDIA_URL = '/media/'

4) Add a designation to the html form itself that you can take multimedia files from it:
5) You add an image hornbeam in the form handler.
6) You solve the problem so that all uploaded files have different names, since by default the file name will be the same. For example, I used the hash of the user's login and his date.
But in general it is better to raise the documentation of the dzhanga, there are some nuances there.

A
Alexander Reutsky, 2017-05-18
@Kanzas

Thanks

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question