def edit_tweet(request, pk): tweet = get_object_or_404(Tweet, pk=pk) form = TweetEditForm(instance=tweet) if request.method == 'POST': form = TweetEditForm(request.POST, instance=tweet) if form.is_valid(): form.save() return redirect('users') return render_to_response('add_user.html', { 'form': form, }, RequestContext(request))
def add_tweet(request): form = TweetEditForm() if request.method == 'POST': form = TweetEditForm(request.POST) if form.is_valid(): tweet = form.save(commit=False) tweet.owner = request.user.get_profile() tweet.save() return redirect('home') return render_to_response('add_tweet.html', { 'form': form, }, RequestContext(request))
def edit_tweet(request, pk): tweet = get_object_or_404(Tweet, pk=pk, owner=request.user.get_profile()) form = TweetEditForm(instance=tweet) if request.method =='POST': form = TweetEditForm(request.POST, instance=tweet) if form.is_valid(): tweeter = form.save(commit=False) tweeter.owner=request.user.get_profile() tweeter.save() return redirect('home') return render_to_response('add_user.html',{ 'form': form, }, RequestContext(request))