Reputation: 41725
Following is a code from https://github.com/jeffbowen/django-logicaldelete/blob/master/logicaldelete/models.py
I am trying to understand what active.boolean = True
does in the code.
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
Upvotes: 1
Views: 47
Reputation: 599778
In Python, functions and methods are objects like anything else. This code is simply adding an attribute boolean
to the active
function, which can be used elsewhere in the code. It doesn't have any significance in and of itself.
In this case, it's used by the admin list display code, to display a nice icon in the list instead of True/False.
Upvotes: 3