I'm trying to use ModelForm ChainedForeignKey and use of my models... #30

Closed
gladson opened this Issue Jun 22, 2012 · 3 comments

Comments

Projects
None yet
3 participants

gladson commented Jun 22, 2012

This works in admin, but when I send to the template through the ModelForm in this way in the template:

form

#!/usr/local/bin/python
# -*- coding: utf-8 -*-
from django import forms
from django.forms import ModelForm
from validoc.certificacao.models import *

class Cadastro_certificado_ecpfForm(forms.ModelForm):
    class Meta:
        model = Cadastro_certificado_ecpf

views

from django.http import HttpResponse, HttpResponseRedirect
from django.contrib.auth.decorators import login_required
from django.shortcuts import render_to_response, get_object_or_404
from django.views.generic.simple import direct_to_template
from validoc.certificacao.forms  import Cadastro_certificado_ecpfForm as ECPFForm

def create_ecpf_post(request):
    if request.method == 'POST':
       form = ECPFForm(request.POST)
       if form.is_valid():
            return HttpResponseRedirect('/add_ecpf/')
    else:
        form = ECPFForm()

    return direct_to_template(request,
                              template='certificacao/add_ecpf.html',
                              extra_context={'form':form} )

template

<form method='post' action='.'>{% csrf_token %}
       {{ form.as_p }}
<input type='submit'>
</form>

Does not work as the admin, what am I doing wrong?

Exit (by blag): Updated formatting to use GFM.

gladson commented Jun 22, 2012

I forgot too...
It makes the filter and does not bring the data as it does...

Contributor

SalahAdDin commented May 22, 2015

Could you fix it?

Collaborator

blag commented Oct 13, 2016

Closing due to inactivity. Feel free to reopen if this is still an issue.

@blag blag closed this Oct 13, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment