Best practices on saving in a view, based on example code

前端 未结 2 1910
悲哀的现实
悲哀的现实 2021-02-11 08:30

I\'m new to Django and looking for best practices on the code I just wrote (below). The code currently exists in my view.py and simply creates a new event. Being familiar with o

2条回答
  •  悲哀的现实
    2021-02-11 09:08

    I think this looks great. You have followed the conventions from the docs nicely.

    Moving request.user to a model would certainly be an anti pattern - a views function is to serve in the request/response loop, so access this property here makes sense. Models know nothing of requests/responses, so it's correct keep these decoupled from any view behavior.

    Only thing that I noticed was creating a category variable out only to be used in construction of the Event, very minor.

提交回复
热议问题