def edit_news(request, id): if request.user.is_authenticated()==False: return HttpResponse("<h2>Для виконання операції, авторизуйтесь</h2>") a = News.objects.get(pk=id) if request.method == 'POST': form = NewsForm(request.POST, instance=a) if form.is_valid(): title = form.cleaned_data['title'] text = form.cleaned_data['text'] link = form.cleaned_data['link'] author = form.cleaned_data['author'] category = form.cleaned_data['category'] comm = form.cleaned_data['comments'] a.title=title a.text=text a.date=a.date a.link=link a.author=author a.category=category a.user=request.user a.save() return HttpResponseRedirect('/') else: form = NewsForm(instance=a) photo1 = Photo.objects.random() photo2 = Photo.objects.random() vars = {'weblink': 'news_add.html', 'sel_menu': 'main', 'photo1': photo1, 'photo2': photo2, 'entry': get_funn(), 'form': form} calendar = embeded_calendar() vars.update(calendar) return render_to_response('index.html', vars, context_instance=RequestContext(request, processors=[custom_proc]))
def add_news(request): if request.user.is_authenticated()==False: return HttpResponse("<h2>Для виконання операції, авторизуйтесь</h2>") a = News() if request.method == 'POST': form = NewsForm(request.POST, instance=a) if form.is_valid(): title = form.cleaned_data['title'] text = form.cleaned_data['text'] # date = form.cleaned_data['date'] link = form.cleaned_data['link'] author = form.cleaned_data['author'] category = form.cleaned_data['category'] comm = form.cleaned_data['comments'] # user = form.cleaned_data['user'] n = News(title=title, text=text, date=datetime.datetime.now(), link=link, author=author, category=category, user=request.user) #n.comments.add(comm) n.save() return HttpResponseRedirect('/') else: form = NewsForm(instance=a, initial={'author': request.user }) photo1 = Photo.objects.random() photo2 = Photo.objects.random() vars = {'weblink': 'news_add.html', 'sel_menu': 'main', 'photo1': photo1, 'photo2': photo2, 'entry': get_funn(), 'form': form} calendar = embeded_calendar() vars.update(calendar) return render_to_response('index.html', vars, context_instance=RequestContext(request, processors=[custom_proc]))