What is @property
in Django?
Here is how I understand it: @property
is a decorator for methods in a class that gets the value in the method.
But, as I understand it, I can just call the method like normal and it will get it. So I am not sure what exactly it does.
Example from the docs:
from django.db import models
class Person(models.Model):
first_name = models.CharField(max_length=50)
last_name = models.CharField(max_length=50)
birth_date = models.DateField()
def baby_boomer_status(self):
"Returns the person's baby-boomer status."
import datetime
if self.birth_date < datetime.date(1945, 8, 1):
return "Pre-boomer"
elif self.birth_date < datetime.date(1965, 1, 1):
return "Baby boomer"
else:
return "Post-boomer"
@property
def full_name(self):
"Returns the person's full name."
return '%s %s' % (self.first_name, self.last_name)
What is the difference of if it is there vs if it isn't?