2

장고 프로젝트와 관련된 데이터베이스를 정규화하고 다른 테이블로 필드를 이동합니다. 구현 과정의 일부로, 실제로 열을 제거하기 전에 새 테이블을 추가 한 후 이전 특성을 사용하려고하면 내 동료에게 사용 중단 경고를 표시하고 싶습니다.django 모델의 필드 사용 중단

class Asset(Model): 
    model = models.CharField(max_length=64, blank=True, null=True) 
    part_number = models.CharField(max_length=32, blank=True, null=True) # this will be a redundant column to be deprecated 
    company = models.ForeignKey('Company', models.CASCADE, blank=True, null=True) # this will be a redundant column to be deprecated 
    # other database fields as attributes and class methods 

나의 이해는 내가 어딘가에 클래스 warnings.warn('<field name> is deprecated', DeprecationWarning)의 라인을 따라 뭔가를 추가해야합니다,하지만 난 그것을 어디에 추가 할 것입니다?

+0

필드를 속성으로 변경하고 거기에서 경고를 처리하고 가능한 경우 적절한 값을 반환 할 수 있습니다. –

답변

0

나는 이것과 비슷한 것을한다. 필드를 속성으로 바꾸고 경고를 처리한다. 필드에서 필터를 작성한 쿼리는 여전히 파기됩니다. 인스턴스에서 속성에 액세스하는 데 도움이됩니다.

class NewAsset(Model): 
    model = models.CharField(max_length=64, blank=True, null=True) 

class Asset(Model): 
    @property 
    def model(self): 
     log.warning('Stop using this') 
     return NewAsset.model 
+0

불행히도 기존 기능을 깨뜨릴 위험은 없습니다. – ccs