장고 응용 프로그램 내에서 요청을 가져 와서 결과를 반환하는 매개 변수를 구문 분석하는 함수가 있습니다. 예를 들어키워드 인수/사전
,이 같은 : 다음 만들거나 해당 이벤트를 업데이트하거나 내 모델 내에서 방법이 사전을 통과하고있어
def parse_event_parameters(request):
"""
Parse the parameters for a given event
from a request and return the result
as a dictionary of strings.
"""
try:
request_params = {
'event_id': id,
'start_date': request.POST[id + '_start_date'],
'end_date': request.POST[id + '_end_date'],
'shift_type': request.POST[id + '_shift_type'],
'rec_type': request.POST[id + '_rec_type'],
'event_length': request.POST[id + '_event_length'],
'event_pid': request.POST[id + '_event_pid'],
}
except KeyError, err:
raise err
return request_params
.
이super(Event, self).update(event_id, start_date,
end_date, shift_type, rec_type,
event_length, event_pid, employee_id)
슈퍼 클래스는 기본적으로 요청의 값을 확인하고 모델에 저장합니다 다음과 같이
e.update(**parameters)
는 일단 거기, 업데이트 방법은 수퍼 클래스를 호출합니다. 이제 모델에 다른 열을 추가하고 각 메소드를 업데이트해야합니다.
저는 장고를 처음 접했지만이 방법이 가장 깨끗한 것처럼 보이지 않습니다.
좀 더 우아한 접근 방법이 있습니까? 각 방법을 통해 사전을 유지해야하며 압축을 풀어야합니까? 당신이 ModelForms를 사용한다처럼
을 (HTTP : //codereview.stackexchange .com /), 코드 및 스타일 작업에 대해 이야기하고 있습니다. –