Opened 15 years ago

Closed 15 years ago

#12253 closed (invalid)

Problem with ModelForm

Reported by: Jorge Owned by: nobody
Component: Forms Version: 1.1
Severity: Keywords: ModelForms
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: yes
Needs tests: no Patch needs improvement: yes
Easy pickings: no UI/UX: no

Description

hi i have a problem when i try to render my form without information . so my code is :

models.py


class Obra(models.Model):
	
	cod_obra= models.CharField("código da obra",max_length=15,primary_key=True)
	nome_da_empreitada= models.CharField(max_length=100)
	data_de_incio = models.DateField("data de início")
	data_de_fim  = models.DateField()
	local = models.CharField(max_length=20)
	morada = models.CharField(max_length=200)
	codigo_postal = models.CharField("código postal",max_length=10)
	adjudicacao= models.DecimalField("ajudicação",max_digits=12,decimal_places=3)
	trabalho_a_mais= models.DecimalField(max_digits=8,decimal_places=2,default=0.00)
	trabalho_a_menos= models.DecimalField(max_digits=8,decimal_places=2,default=0.00)
	data_de_entrada=models.DateField("data de inserção",default=date.today())
	#ForeignKey
	cliente= models.ForeignKey(Cliente)
	def __unicode__(self):
			return '%s %s'%(self.cod_obra,self.nome_da_empreitada)
	
	class Meta:
			verbose_name= u'Obra'

forms.py

from django.forms import ModelForm

class ObraForm(ModelForm):
	class meta: 
		model=Obra

views.py

def nova_obra(request):
	if request.GET.has_key('ajax'):
		n_obra= ObraForm(instance=Obra())
		return render_to_response('nova_obra.html',locals())
	
	return HttpResponse("ERROR ver o HttpResponse")

nova_obra.html :

<form method="post" action=".">
	{{n_obra.as_p}}
	</form>
    <p><input id="save_obra"type="submit" value="Gravar Obra" /></p>

when a render the page i don't get any form... only the input button .... can someone tell me why ? plz
when i make this in the view print n_obra.as_p i get this : <bound method ObraForm.as_p of <si_andrade.andrade_e_almeida.forms.ObraForm object at 0x1020bd810>>

Change History (5)

comment:2 by Alex Gaynor, 15 years ago

Resolution: invalid
Status: newclosed

Trac is not for asking support questions, please use either the django-users mailing list or the #django channel on IRC.

comment:3 by Jorge, 15 years ago

Component: UncategorizedForms
Keywords: ModelForms added
Needs documentation: set
Patch needs improvement: set

comment:4 by Jorge, 15 years ago

Resolution: invalid
Status: closedreopened

i realy can't find any help. it could be a bug.

in reply to:  4 comment:5 by Ramiro Morales, 15 years ago

Resolution: invalid
Status: reopenedclosed

Replying to dragon_men:

i realy can't find any help.

That's no reason to search for support here.

it could be a bug.

How do you expect this to work

n_obra= ObraForm(instance=Obra())

if you are not providing values for all of these model fields when trying to create an Obra model instance?:

nome_da_empreitada= models.CharField(max_length=100)
data_de_incio = models.DateField("data de início")
data_de_fim  = models.DateField()
local = models.CharField(max_length=20)
morada = models.CharField(max_length=200)
codigo_postal = models.CharField("código postal",max_length=10)
adjudicacao= models.DecimalField("ajudicação",max_digits=12,decimal_places=3)

Try to fix you code first by tracing and debugging every step and confirming every assumption.

Please don't reopen this ticket.

Also, when you post to the support channels try to create a minimal test case, pasting all you model definition doesn't help people to help you.

Note: See TracTickets for help on using tickets.
Back to Top