Пример #1
0
def advice_edit(request, id):
    try:
        content = Content.objects.get(id=id)
    except Content.DoesNotExist:
        content = None
    if content and request.method == "GET":
        form = DisscussionForm(instance=content)
    elif content and request.method == "POST":
        form = DisscussionForm(request.POST, instance=content)
        if form.is_valid():
            advice = form.save()
            images = request.POST.get('images')
            images_list = images.split(',')
            gallery, created = Gallery.objects.get_or_create(content=advice)
            if images_list[0] != "":
                images = Image.objects.filter(id__in=images_list)
                gallery.images = images
            else:
                gallery.images = []
            return HttpResponseRedirect(reverse('advice'))
        else:
            return render(request, 'manager/advice_edit.html', locals())
    else:
        raise Http404
    return render(request, 'manager/advice_edit.html', locals())
Пример #2
0
def advice_add(request):
    form = DisscussionForm()
    if request.method == "POST":
        form = DisscussionForm(request.POST)
        if form.is_valid():
            advice = form.save()
            images = request.POST.get('images')
            images_list = images.split(',')
            gallery, created = Gallery.objects.get_or_create(content=advice)
            if images_list[0] != "":
                images = Image.objects.filter(id__in=images_list)
                gallery.images = images
            else:
                gallery.images = []
            return HttpResponseRedirect(reverse('advice'))
    return render(request, 'manager/advice_add.html', locals())