def add_news_view(request): if request.method == 'POST': form = NewsForm(request.POST) if form.is_valid(): form.save() return redirect('newsfeed') else: form = NewsForm() return TemplateResponse(request, 'newsfeed/news_add.html', {'form': form})
def edit_news_view(request, news_id): news_item = get_object_or_404(News, id=news_id) if request.method == 'POST': form = NewsForm(request.POST, instance=news_item) if form.is_valid(): form.save() return redirect('newsfeed') else: form = NewsForm(instance=news_item) return TemplateResponse(request, 'newsfeed/news_edit.html', {'form': form})