python: editable content via object 

# Create your views here.
from django.http import HttpResponse
from django.template import Context, Template from django.shortcuts import render_to_response from django import forms from django.shortcuts import render, get_object_or_404 from django.http import HttpResponseRedirect

from forms import LogTypeForm
from models import LogType

def new_logtype(request):


if request.method == 'POST':
form = LogTypeForm( request.POST )
if form.is_valid():
#form = LogTypeForm( request.POST, instance=LogType )
#print str(form)
print "Saving form..."
logtype = form.save()
print logtype
print logtype.id
print dir(logtype)
else:
form = LogTypeForm()
print str(form)

return render(request, 'logcheck_index.html', {'form': form})

def edit_logtype(request, logtype_id):
logtype_model = get_object_or_404(LogType, id=logtype_id)

if request.method == 'POST':
form = LogTypeForm( request.POST, instance=logtype_model )
if form.is_valid():
#form = LogTypeForm( request.POST, instance=LogType )
#print str(form)
print "Saving form..."
logtype = form.save()
print logtype
print logtype.id
print dir(logtype)
else:
form = LogTypeForm(instance=logtype_model)
print str(form)
return render(request, 'logcheck_index.html', {'form': form})



[ add comment ] ( 4 views )   |  [ 0 trackbacks ]   |  permalink

<<First <Back | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | Next> Last>>