def add_tip(request): if request.POST: form = TipForm(request.POST) try: form.save() return HttpResponseRedirect(reverse('tip-mytips')) except: pass return mytips(request, form) return HttpResponseRedirect(reverse('tip-mytips'))
def update_tip(request): if request.POST: id = request.POST.get('id') tip = get_object_or_404(Tip, id=id, author=request.user) form = TipForm(request.POST, instance=tip) try: form.save() return HttpResponseRedirect(reverse('tip-mytips')) except: pass context = {'form':form , 'active_menu':'mytips'} return direct_to_template(request, 'edit.html', context)
def update_tip(request): if request.POST: id = request.POST.get('id') tip = get_object_or_404(Tip, id=id, author=request.user) form = TipForm(request.POST, instance=tip) try: form.save() return HttpResponseRedirect(reverse('tip-mytips')) except: pass context = {'form': form, 'active_menu': 'mytips'} return direct_to_template(request, 'edit.html', context)
def mytips(request, form=None): if form == None: form = TipForm() tips = Tip.objects.filter(author=request.user) bookmarked_tips = Bookmark.objects.filter(user=request.user) context = { 'tips': tips, 'bookmarked_tips': bookmarked_tips, 'form': form, 'active_menu': 'mytips' } return direct_to_template(request, 'mytips.html', context)
def show_edit_form(request, id, slug=None): tip = get_object_or_404(Tip, id=id, author=request.user) context = {'form': TipForm(instance=tip), 'active_menu': 'mytips'} return direct_to_template(request, 'edit.html', context)