以下是来自https://github.com/jeffbowen/django-logicaldelete/blob/master/logicaldelete/models.py的代码
我试图了解active.boolean = True
代码中的内容。
class Model(models.Model):
"""
This base model provides date fields and functionality to enable logical
delete functionality in derived models.
"""
date_created = models.DateTimeField(default=timezone.now)
date_modified = models.DateTimeField(default=timezone.now)
date_removed = models.DateTimeField(null=True, blank=True)
objects = managers.LogicalDeletedManager()
def active(self):
return self.date_removed == None
active.boolean = True # <------------------- HERE
def delete(self):
self.date_removed = timezone.now
self.save()
class Meta:
abstract = True