def createLostAndFound(request): if request.method != 'POST' : pform = PublicationForm() lform = LostFoundForm() else: pform = PublicationForm(request.POST) lform = LostFoundForm(request.POST) if pform.is_valid() and lform.is_valid(): savelostandfound(lform, pform, request.user) return HttpResponseRedirect('/publications/lostandfound') return render(request, 'publications/foundlost_create.html', {'pform':pform, 'lform':lform})
def editLostAndFound(request, lostandfoundId): publication = get_object_or_404(Publication, pk=lostandfoundId) if publication.author.user != request.user: return HttpResponseForbidden() lostandfound= publication.lostandfound if request.method != 'POST': pform = PublicationForm(instance=publication) lform = LostFoundForm(instance=lostandfound) else: pform = PublicationForm(request.POST, instance = publication) lform = LostFoundForm(request.POST, instance = lostandfound) if pform.is_valid() and lform.is_valid(): savelostandfound(lform, pform, request.user) return HttpResponseRedirect('/publications/lostandfound') return render(request, 'publications/foundlost_create.html', {'pform':pform, 'lform':lform})