Skip to content

Instantly share code, notes, and snippets.

@fchevitarese
Created June 10, 2015 13:55
Show Gist options
  • Select an option

  • Save fchevitarese/323ea98f2b65c039998d to your computer and use it in GitHub Desktop.

Select an option

Save fchevitarese/323ea98f2b65c039998d to your computer and use it in GitHub Desktop.
from django.shortcuts import render, render_to_response, get_object_or_404, HttpResponseRedirect, HttpResponse, redirect
from django.template import RequestContext, loader
from django.contrib.auth.decorators import login_required
from django.core.urlresolvers import reverse_lazy
from django.views.generic import UpdateView
from models import Cadastro
from .forms import CadastroForm
# Create your views here.
@login_required
def index(request):
return render(request, 'index.html')
@login_required
def suporte(request):
return render(request, 'suporte.html')
class MeusDados(UpdateView):
model = Cadastro
form_class = CadastroForm
success_url = reverse_lazy('index')
@login_required
def meus_dados(request):
if request.method == 'POST':
cadastro = CadastroForm(request.POST, instance=CadastroForm(user_id=request.user))
cadastro.user_id = request.user
if cadastro.is_valid():
cadastro.save()
else:
cadastro = CadastroForm()
return render(request, 'meus_dados.html', {'cadastro':cadastro})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment