Django - Non-verbose ways to save POST data -
i'm wondering whether there better way take data , write database. 'standard' way feels little verbose me. question how rewrite in less redundant way. mean works, feel isn't 'correct' way...
def post(self, request, **kwargs): ticket = ticket.objects.get(id = ticket_id) comment = comment() if request.method == 'post': if 'solve_comment' in request.post: ticket.state_id = 5 text = request.post['solve_comment'] comment.text = text 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()
the issues if there say, 5+inputs in form creates massive wall of code. suggestions great!
use createview generic view. there's updateview updating existing objects.
in experience, it's rare not able use generic view in django, , form handling they're quickest way implement something.
Comments
Post a Comment