0
class myClass (models.Model):
  related_operation = models.ForeignKey('self', null = True)

  __related_operation = None

  def save(self, force_insert=False, force_update=False):
    if self.related_operation != self.__related_operation:
      del self.__related_operation

    super(Operation, self).save(force_insert, force_update)
    self.__related_operation = self.related_operation

我应该使用 del self.__related_operation 还是应该使用 self.__related_operation.delete()?

4

1 回答 1

1

del self.__related_operation将尝试删除实例的__related_operation属性。我不确定你为什么要这样做。

如果要从数据库中删除对象,请使用该delete()方法。

于 2012-09-19T21:08:17.377 回答