2014-07-23 69 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