0
class PositionModel(models.Model):
xpos = models.IntegerField()
ypos = models.IntegerField()
def relative(self, x, y):
self.__class__.objects.filter(xpos = self.xpos + x,
ypos = self.ypos + y)
class Meta:
abstract = True
本示例允許您在多個不同模型中繼承PositionModel,然後使用relative(x,y)函數根據模型執行查詢的孩子。Django:使用抽象父模型中子模型的管理器
Django是否有其他一些首選的方法在使用孩子的管理器的抽象模型中編寫函數?