我有一个自定义表格如下
class ticketform( BootstrapForm ):
class Meta:
layout = (
Fieldset( "", "project", "manager", "cc_to", "urgency", "deadline", "subject", "steps", "result", "desc", "file" ),
)
project = forms.CharField( max_length = 100, label = "Project", help_text = "Project this request is related to" )
manager = UserModelChoiceField( queryset = User.objects.filter( is_active = True ).order_by( 'first_name' ), label = "Manager",
help_text = "Immediate superior or project manager", required = True )
cc_to = UserMultipleSelectField( queryset = User.objects.filter( is_active = True ).order_by( 'first_name' ), label = "CC To",
widget = widgets.FilteredSelectMultiple( "Users", is_stacked = True ), required = False )
OPTIONS = (
( 'Critical', 'Critical' ),
( 'Major', 'Major' ),
( 'Minor', 'Minor' ),
)
urgency = forms.ChoiceField( choices = OPTIONS, label = "Urgency", help_text = "Urgency of the request" )
deadline = forms.CharField( widget = widgets.AdminSplitDateTime(), label = "Deadline",
help_text = "When should this ticket be completed", required = True )
subject = forms.CharField( max_length = 100, label = "Subject", help_text = "Ticket Subject" )
steps = forms.CharField( widget = forms.Textarea, label = "Steps", help_text = "Reproducible error/feature Steps" )
result = forms.CharField( widget = forms.Textarea, label = "Result", help_text = "Expected Result" )
desc = forms.CharField( widget = forms.Textarea, label = "Description", help_text = "Detailed Description" )
file = forms.FileField( label = "File", help_text = "Attach File Max size 10MB", required = False )
我的视图中有以下代码来填充表单以供查看
def view_ticket( request, ticket_id ):
ticket = Ticket.objects.filter( pk=ticket_id )[0]
dict = {'project' : ticket.project,
'manager' : ticket.manager.pk,
'urgencry': ticket.urgency,
'deadline': ticket.deadline,
'subject' : ticket.subject,
'steps' : ticket.steps,
'result' : ticket.result,
'desc' : ticket.detailed_disc,
'file' : ticket.attachments,
'cc_to' : ticket.cc_to.all()
}
form = ticketform( dict )
return render_to_response( 'form/request.html', {'form':form,
},
mimetype="text/html", context_instance=RequestContext( request ) )
现在发生的事情是该deadline
字段没有被填充(所有其他字段都被填充得很好)。尽管我将字典中的值传递给它。有没有办法预先填充AdminSplitDateTime()
表单上的字段?