-
Notifications
You must be signed in to change notification settings - Fork 0
/
README
71 lines (52 loc) · 1.92 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
Yet another plugin for uploading files to the server using
Django and JQuery.
Based on jQuery-File-Upload written by Sebastian Tschan
(https://github.com/blueimp/jQuery-File-Upload).
Requirements
- PIL (Python Imaging Library) for thumbnails generation
- Django 1.4 +
Installation
1. Add app to your INSTALLED_APPS:
INSTALLED_APPS = (
...
'jquery_uploader',
...
)
2. Register urls in your root urls.py:
urlpatterns = patterns('',
...
url(r'^jquery_uploader/', include('jquery_uploader.urls')),
...
)
3. If necessary, you must configure the directory for temporary storage
of uploaded files and link to it, and also the size of created thumbnails:
# by default
JQUERY_UPLOADER_ROOT = 'jquery_uploader'
JQUERY_UPLOADER_URL = 'jquery_uploader'
JQUERY_UPLOADER_PREVIEW_MAX_HEIGHT = 140
JQUERY_UPLOADER_PREVIEW_MAX_WIDTH = 200
JQUERY_UPLOADER_MAX_FILE_SIZE = 10485760
4. Simple example use in the project:
4.1. In template:
<form action="/your-url-for-upload-and-save/" method="POST">
{% csrf_token %}
{% load jquery_uploader_tags %}
{% jquery_uploader_simple %}
{# or for JQuery UI {% jquery_uploader_jqueryui %} #}
{# or for Bootstrap {% jquery_uploader_bootstrap %} #}
<input type="submit" />
</form>
Also, for certain cases, you can specify a maximum file size with the templatetag argument:
{% jquery_uploader_simple 1048576 %}
4.2. In model and in views (downloaded files are returned by variable 'jquery_uploader_files'):
# model
class Photo(models.Model):
photo = models.ImageField(upload_to='photo')
# view
from jquery_uploader.utils import save_to_model
if request.method == 'POST':
files = request.POST.getlist('jquery_uploader_files', None)
for f in files:
p = Photo()
save_to_model(p.photo, f)
p.save()