Code

Opened 5 years ago

Closed 5 years ago

#12253 closed (invalid)

Problem with ModelForm

Reported by: dragon_men 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: UI/UX:

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>>

Attachments (0)

Change History (5)

comment:1 Changed 5 years ago by dragon_men

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

comment:2 Changed 5 years ago by Alex

  • Resolution set to invalid
  • Status changed from new to closed

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

comment:3 Changed 5 years ago by dragon_men

  • Component changed from Uncategorized to Forms
  • Keywords ModelForms added
  • Needs documentation set
  • Patch needs improvement set

comment:4 follow-up: Changed 5 years ago by dragon_men

  • Resolution invalid deleted
  • Status changed from closed to reopened

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

comment:5 in reply to: ↑ 4 Changed 5 years ago by ramiro

  • Resolution set to invalid
  • Status changed from reopened to closed

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.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.