开发者

Getting from a model to the model type's verbose name

开发者 https://www.devze.com 2022-12-17 19:11 出处:网络
I\'ve got an instance of a model FooBar - how do I get the naturalised type Foo Bar for display to the user, making sure to 开发者_运维百科use the class\'s verbose_name if one is set in the Meta optio

I've got an instance of a model FooBar - how do I get the naturalised type Foo Bar for display to the user, making sure to 开发者_运维百科use the class's verbose_name if one is set in the Meta options. e.g.:

class FooBar(models.Model):
  title = models.CharField(max_length = 100)

  class Meta:
    verbose_name = 'Spaghetti Monster'

How do I get 'Spaghetti Monster' from an instance of a FooBar?


foobar._meta.verbose_name

0

精彩评论

暂无评论...
验证码 换一张
取 消