0

아래 코드는 Python 프로그램에서 일반적으로 수행 할 작업을 보여줍니다. 응용 프로그램 엔진이 속성을 시작하는 것을 허용하지 않기 때문에 Google 애플리케이션 엔진에서 ndb 데이터 저장소와 함께 @property 사용

class LogOnline(ndb.Model): 
    _timeOnline = ndb.DateTimeProperty(default=None) 

    @property 
    def timeOnline(self): 
     return self._timeOnline 

    @timeOnline.setter 
    def timeOnline(self, dateTime): 
     self._timeOnline = dateTime 
     #set memcache with all current online users 
     #..... 

그러나이 코드가 작동하지 않는 '_' 또한 나는에 대한 쿼리를 수행 할 때이 문제를 제공 할 수 있기 때문에 이러한 형태의 아키텍처 나쁜 관행이 될 수 느낀다 수업.

가장 좋은 방법은 무엇입니까?

답변

1

할 수있는 일은 timeOnline을 밑줄없는 속성으로 지정하고 _post_put_hook을 추가하여 memcache를 업데이트하는 것입니다.

class LogOnline(ndb.Model): 
    timeOnline = ndb.DateTimeProperty(default=None) 

    def _post_put_hook(self, future): 
     future.get_result() #wait untill the PUT operation has completed 
     #set memcache with all current online users 
     ... 
+0

고마워요. 제가 찾고있는 것이고 결국 _pre_put_hook (self)를 사용하게되었습니다. –

+0

왜? 정확한 유스 케이스는 모르지만 _post_put_hook에서는 날씨가 날씨에 따라 결정을 내릴 수 있습니다. – bigblind

관련 문제