- Author:
- dodolboks
- Posted:
- December 31, 2009
- Language:
- Python
- Version:
- 1.1
- Score:
- 1 (after 3 ratings)
example formset views for multiple image upload
hope its useful ...
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 | @login_required
def produks(request, name):
entry = get_object_or_404(Entry, name=name)
UploadFormSet = formset_factory(UploadForm, extra=4)
if request.method == "POST":
form = ProdukForm(entry, request.POST, request.FILES)
formset = UploadFormSet(request.POST, request.FILES)
if form.is_valid() and formset.is_valid() :
text = form.cleaned_data['text']
html = sanitize_html(markdowner.convert(text))
title = form.cleaned_data['title']
produk = Produk(
entry = entry,
title = title,
kategori = form.cleaned_data['kategori'],
keyword = form.cleaned_data['keyword'],
text = text,
html = html,
user = request.user,
)
produk.save()
for form in formset.cleaned_data:
image= form['image']
photo = Photo (title = image.name, image= image, produk = produk , entry=entry)
photo.save()
return HttpResponseRedirect(produk.get_absolute_url())
else:
form = ProdukForm(entry)
formset = UploadFormSet()
return render_to_response('shop/produkadd.html', {
'form' : form,
'formset' : formset,
'entry' : entry
}, context_instance=RequestContext(request))
|
More like this
- Template tag - list punctuation for a list of items by shapiromatron 10 months, 2 weeks ago
- JSONRequestMiddleware adds a .json() method to your HttpRequests by cdcarter 10 months, 3 weeks ago
- Serializer factory with Django Rest Framework by julio 1 year, 5 months ago
- Image compression before saving the new model / work with JPG, PNG by Schleidens 1 year, 6 months ago
- Help text hyperlinks by sa2812 1 year, 6 months ago
Comments
Please login first before commenting.