1๐
โ
I would use properties
class Listing(models.Model):
slug = models.SlugField(unique=True)
title = models.CharField(max_length=100)
post_date = models.DateField(auto_now_add=True, auto_now=False)
locality = models.CharField(max_length=100)
@property
def default_title(self):
return '%s house in %s' % (self.title, self.locality)
@property
def default_slug(self):
return '%s' % slugify(self.default_title)
one advantage of property is that you can use it in template as if it were a normal class attribute:
{{ listing.default_title }}
๐คdoniyor
Source:stackexchange.com