I have a @property
called name
in my
class Person(models.Model):
first_name = models.CharField("Given name", max_length=255)
last_name = models.CharField("Family name ", max_length=255)
@property
def name(self):
return "%s %s" % (self.first_name, self.last_name)
Is it easily possible to specify the verbose_name
for this property?
A verbose_name
cannot be set for a @property
called name
, but short_description
can be used instead:
class Person(models.Model):
first_name = models.CharField('Given name', max_length=255)
last_name = models.CharField('Family name ', max_length=255)
@property
def name(self):
return '%s %s' % (self.first_name, self.last_name)
name.fget.short_description = 'First and last name'
This may not work with all Django admin classes, but it will work with the basic one.
This uses the fget
object created by @property
and sets a short_description
property in it. Django looks for that property and uses it if available.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With