2014-07-23 49 views
0

我对django很新,但意识到这种类型的表单处理非常冗长。有什么办法可以缩短这样的陈述吗?我看着ModelForms,但我不确定它适用于这里(也许我错了?)。使用Django Forms删除详细表单处理

if 'solve_comment' in request.POST: 
     ticket.state_id = 5 
     text = request.POST['solve_comment'] 
     comment.text = text + " (descended back to Level 1)" 
     ticket.group_id = 6 
     comment.comment_type = "solving_note" 
     comment.content_type = ContentType.objects.get(id=114) 
     comment.object_id = ticket.id 
     comment.created_by_id = request.user.id 
     comment.save() 
     ticket.save() 
    if 'closing_note' in request.POST: 
     ticket.state_id = 6 
     text = request.POST['closing_note'] 
     ticket_issue = request.POST['ticket_issue'] 
     comment.text = text + (" (%s)" %ticket_issue) 
     comment.comment_type = "closing_note" 
     comment.content_type = ContentType.objects.get(id=114) 
     comment.object_id = ticket.id 
     comment.created_by_id = request.user.id 
     comment.save() 
     ticket.save() 
    if 'private_note' in request.POST: 
     text = request.POST['private_note'] 
     comment.text = text 
     comment.comment_type = "private_note" 
     #this line needs to be fixed 
     comment.content_type = ContentType.objects.get(id=114) 
     comment.object_id = ticket.id 
     comment.created_by_id = request.user.id 
     comment.save() 
    if 'reopen-ticket-button' in request.POST: 
     ticket.state_id = 2 
     ticket.save() 
    if 'hold-ticket-button' in request.POST: 
     ticket.state_id = 4 
     ticket.save() 
    if 'take_ownership' in request.POST: 
     ticket.assignee_id = request.user.id 
     if ticket.state_id == 1: 
      ticket.state_id = 2 
     ticket.save() 

回答

2

把手样式,你有一个API