파이썬/Django

unsupported operand type(s) for -: 'NoneType' and 'NoneType'

바리새인 2021. 3. 7. 20:14

models.py에 아래와 같이 있고,

    def getHeight(self) :
        return self.coords_4 - self.coords_2

admin.py에서 관련 model을 아래와 같이 TabularInline로 호출하는 경우

fields = ['id','getBoxLink','char','getHeight','coords_1','coords_2','coords_3','coords_4','page']

저런 에러가 발생함

getHeight에 로그를 찍어보니, 마지막 row 뒤에 None으로 row가 하나 더 찍힘

아래와 같이 해결함

정확한 원인은 모르겠음

    def getHeight(self) :
        if self.id != None :
            return self.coords_4 - self.coords_2
        return None