雖然我知道如何製作它,並且搜索了用於比較我的代碼的示例,但我無法得到爲什麼我無法調用其父母的__str__
內部調用__str__
的模型。我得到一個RuntimeError: maximum recursion depth exceeded in __subclasscheck__
,這不應該發生。無法在Django中自定義__str__調用父級的__str__
這是我的代碼如下。不,這可能會影響它的抵押品工作:
@python_2_unicode_compatible
class A(models.Model):
def __str__(self):
return self.attr
@python_2_unicode_compatible
class B(A):
def __str__(self):
return "%s - %s" % (super(B, self).__str__(), self.attr_two)
此代碼將工作。您需要顯示真實的代碼和回溯(或直到它開始重複)。 –