2013-03-22 4 views
0

아래 프로세스가 완료되면 모델 필드에서 상태를 업데이트 할 방법이 필요합니다.장고 모델 내에서 상태 업데이트

views.py, 내 모델에서 내가

batch.complete_update() 

내 문제 야한다 그래서 내가보기에이 같은 일을 생각하고

#If we had a POST then get the request post values. 
    if request.method == 'POST': 
     batches = Batch.objects.for_user_pending(request.user) 
     for batch in batches: 
      ProcessRequests.delay(batch) 

... 방법을 모르겠다. 조금 도움이 필요하다.

이것은 내가 지금까지 한 일입니다 ...

나는 다음 모델 기능이 def complete_update(self):라고

STATUSES = (
    ('Pending', 'Pending'), 
    ('Complete', 'Complete'), 
    ('Failed', 'Failed'), 
    ('Cancelled', 'Cancelled'), 
) 

을 만들어,하지만 난 그것을에서 필드를 업데이트하는 방법을 잘 모르겠어요 상태를 확인한 다음 모델에서 모두 저장하십시오.

미리 감사드립니다.

추신 : 이것이 올바른 방법인가요?

편집을해야

답변

1
class Batch(model.Model): 
    STATUSES_CHOICES = (
     ('Pending', 'Pending'), 
     ('Complete', 'Complete'), 
     ('Failed', 'Failed'), 
     ('Cancelled', 'Cancelled'), 
    ) 
    status = models.CharField(max_length=25, choices=STATUS_CHOICES) 
    # The rest of the fields.. 

    def complete_update(self): 
     self.status = 'Complete' 
     self.save() 

: karthikr post_save에서 언급 한 바와 같이이

에 대해 갈 수있는 더 좋은 방법이 될 수있다