0

I'm pretty new to django but realize that this type of form handling is very verbose. Is there any way to shorten statements such as this? I looked into ModelForms but I'm not sure its applicable here (maybe I'm wrong?).

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

1 Answer 1

2

Handle forms with Django Forms, you have an API

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.